<!-- 博客 - 页面布局 > 上中下 -->



<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>
<!-- 博客 - 导航栏上方 -->


<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/blog/img/fluid.png">
  <link rel="icon" href="/blog/img/icon/dw.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Memory">
  <meta name="keywords" content="">

  
    <meta name="description" content="Memory 用户中心开发基本流程">
<meta property="og:type" content="article">
<meta property="og:title" content="项目志录：Memory 用户中心中心开发文档">
<meta property="og:url" content="https://test.atomgit.net/blog/2023/03/17/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20%E7%94%A8%E6%88%B7%E4%B8%AD%E5%BF%83%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/index.html">
<meta property="og:site_name" content="Memory&#39;s blog">
<meta property="og:description" content="Memory 用户中心开发基本流程">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://test.atomgit.net/blog/img/artical/brage20240729.jpg">
<meta property="article:published_time" content="2023-03-17T02:05:47.000Z">
<meta property="article:modified_time" content="2023-04-21T14:36:44.000Z">
<meta property="article:author" content="Memory">
<meta property="article:tag" content="项目">
<meta property="article:tag" content="开发经验">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://test.atomgit.net/blog/img/artical/brage20240729.jpg">
  
  
  
  <title>项目志录：Memory 用户中心中心开发文档 - Memory&#39;s blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/blog/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"test.atomgit.net","root":"/blog/","version":"1.9.4","typing":{"enable":true,"typeSpeed":100,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":false,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"appId":"T1hUHH9Ks1ggG9DBE3HgUPpV-gzGzoHsz","appKey":"XFkgzzvzNo3J3uNCbBiSOFKc","server_url":"https://t1huhh9k.lc-cn-n1-shared.com","path":"window.location.pathname","ignore_local":false}},"search_path":"/blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/blog/js/utils.js" ></script>
  <script  src="/blog/js/color-schema.js" ></script>
  

  

  

  

  

  

  

  



  
<meta name="generator" content="Hexo 5.4.2"></head>

<body>
  

  <header>
    <!-- 博客 - 导航栏上方 -->


<div class="header-inner" style="height: 100vh">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/blog/">
      <strong>Memory&#39;s blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                <span>标签</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/playlist/">
                <i class="iconfont icon-music"></i>
                <span>音乐</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/Memos/">
                <i class="iconfont icon-comment "></i>
                <span>说说</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/blog/App/">
                <i class="iconfont icon-mobile"></i>
                <span>咫尺</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                <span>青简</span>
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="http://47.93.135.62:5230/explore">
                    <i class="iconfont icon-images"></i>
                    <span>碎念微光</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/blog/New/">
                    <i class="iconfont icon-bug"></i>
                    <span>匠册详析</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/blog/New/">
                    <i class="iconfont icon-xbox-fill"></i>
                    <span>窗景新编</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/blog/New/">
                    <i class="iconfont icon-steam"></i>
                    <span>戏码幕后</span>
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/blog/New/">
                    <i class="iconfont icon-map"></i>
                    <span>他山随拾</span>
                  </a>
                
              </div>
            </li>
          
        
        
            <li class="nav-item" id="search-btn">
                <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalNotice" aria-label="Search">
                    <i class="iconfont icon-book"></i>
                    <span>公告</span>
                </a>
            </li>
            
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>
 
<div id="banner" class="banner" parallax=true
     style="background: url('/blog/img/artical/brage20240729.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">

    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">

        <div class="h2">
          
            <span id="subtitle" data-typed-text="项目志录：Memory 用户中心中心开发文档"></span>
          
        </div>


        
          <!-- 文章页面 - 顶部信息 -->

<div class="mt-3">
  
  <span class="post-meta mr-2">
    <i class="iconfont icon-author" aria-hidden="true"></i>
    Memory
  </span>
   
  <span class="post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2023-03-17 10:05" pubdate>
      2023年3月17日 上午
    </time>
  </span>
  
</div>

<div class="mt-1">
  
  <span class="post-meta mr-2">
    <i class="iconfont icon-chart"></i>
     38k 字 
  </span>
   
  <span class="post-meta mr-2">
    <i class="iconfont icon-clock-fill"></i>
       94 分钟 
  </span>
     
  <span
    id="leancloud-page-views-container"
    class="post-meta"
    style="display: none"
  >
    <i class="iconfont icon-eye" aria-hidden="true"></i>
    <span id="leancloud-page-views"></span> 次
  </span>

    
</div>


        

        <!-- 添加网站运行时间 -->
        <div class="footer-content" style="background-color: transparent;">
          <div>
            <span id="timeDate"></span>
            <span id="times"></span>
            <script>
            var now = new Date();
            function createtime(){
                var grt= new Date("03/07/2023 00:00:00");//此处修改你的建站时间或者网站上线时间
                now.setTime(now.getTime()+250);
                days = (now - grt ) / 1000 / 60 / 60 / 24;
                dnum = Math.floor(days);
                hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum);
                hnum = Math.floor(hours);
                if(String(hnum).length ==1 ){
                    hnum = "0" + hnum;
                }
                minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
                mnum = Math.floor(minutes);
                if(String(mnum).length ==1 ){
                          mnum = "0" + mnum;
                }
                seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
                snum = Math.round(seconds);
                if(String(snum).length ==1 ){
                          snum = "0" + snum;
                }
                document.getElementById("timeDate").innerHTML = "🚀 &nbsp"+dnum+"&nbsp天";  //此次自定义显示内容
                document.getElementById("times").innerHTML = hnum + "&nbsp小时&nbsp" + mnum + "&nbsp分&nbsp" + snum + "&nbsp秒";
            }  

            if (!window.location.href.includes('/20')) {  
            setInterval("createtime()", 250);  // 只有当URL不包含'specific-page'时，才调用createtime  
            }//此次自定义显示内容
            </script>
          </div>
        </div>

      </div>
      
        <div class="scroll-down-bar">
          <i class="iconfont icon-arrowdown"></i>
        </div>
      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      <!-- 文章页  -->


<div class="container-fluid nopadding-x">

  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar category-bar" style="margin-right: -1rem">
    <!-- 文章页面 - 左边栏所属分类 -->
  

<!-- 文章页 - 文章分类 -->





<div class="category-list">
  
  
    
    
    
    <div class="category row nomargin-x">
      <a class="category-item 
          list-group-item category-item-action col-10 col-md-11 col-xm-11" title="项目志录"
        id="heading-005e56101bc2a873707cb4461a70ded8" role="tab" data-toggle="collapse" href="#collapse-005e56101bc2a873707cb4461a70ded8"
        aria-expanded="true"
      >
        项目志录
        <span class="list-group-count">(12)</span>
        <i class="iconfont icon-arrowright"></i>
      </a>
      
      <div class="category-collapse collapse show" id="collapse-005e56101bc2a873707cb4461a70ded8"
           role="tabpanel" aria-labelledby="heading-005e56101bc2a873707cb4461a70ded8">
        
        
          
  <div class="category-post-list">
    
    
      
      
        <a href="/blog/2023/03/17/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20%E7%94%A8%E6%88%B7%E4%B8%AD%E5%BF%83%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="项目志录：Memory 用户中心中心开发文档"
           class="list-group-item list-group-item-action
           active">
          <span class="category-post">项目志录：Memory 用户中心中心开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/03/24/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20%E4%BC%99%E4%BC%B4%E5%8C%B9%E9%85%8D%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="项目志录：Memory 伙伴匹配系统开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">项目志录：Memory 伙伴匹配系统开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/04/09/%E9%BB%84%E9%87%91%E7%9F%BF%E5%B7%A5%E6%80%80%E6%97%A7%E7%89%88-%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="黄金矿工怀旧版-开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">黄金矿工怀旧版-开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/04/22/%E9%A1%B9%E7%9B%AE%E5%9B%9E%E9%A1%BE%20-%20%E5%AE%9E%E8%B7%B5%E7%BB%8F%E9%AA%8C%E5%92%8C%E6%94%B6%E8%8E%B7%E6%80%BB%E7%BB%93/" title="项目回顾 - 实践经验和收获总结"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">项目回顾 - 实践经验和收获总结</span>
        </a>
      
    
      
      
        <a href="/blog/2023/07/11/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20API%20%E6%8E%A5%E5%8F%A3%E5%BC%80%E6%94%BE%E5%B9%B3%E5%8F%B0%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="项目志录：Memory API 接口开放平台开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">项目志录：Memory API 接口开放平台开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/08/02/PicMemories%20%E5%A3%81%E7%BA%B8%E5%88%86%E4%BA%AB%E5%B0%8F%E7%A8%8B%E5%BA%8F%20-%20%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="PicMemories-开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">PicMemories-开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/08/07/TaskMemories%20-%20%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="TaskMemories-开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">TaskMemories-开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/08/26/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20Search%20%E8%81%9A%E5%90%88%E6%90%9C%E7%B4%A2%E5%B9%B3%E5%8F%B0%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="项目志录：Memory Search 聚合搜索平台开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">项目志录：Memory Search 聚合搜索平台开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/09/10/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20%E7%BC%98%E5%BF%86%E4%BA%A4%E5%8F%8B%E7%A4%BE%E5%8C%BA%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="项目志录：Memory 缘忆交友社区开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">项目志录：Memory 缘忆交友社区开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/2023/10/03/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95%EF%BC%9AMemory%20BI%20%E6%99%BA%E8%83%BD%E5%88%86%E6%9E%90%E5%B9%B3%E5%8F%B0%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3/" title="项目志录：Memory BI 智能分析平台开发文档"
           class="list-group-item list-group-item-action
           ">
          <span class="category-post">项目志录：Memory BI 智能分析平台开发文档</span>
        </a>
      
    
      
      
        <a href="/blog/categories/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95/" class="list-group-item list-group-item-action">
          <span class="category-post">More...</span>
        </a>
        
  </div>

        
      </div>
    </div>
  
</div>

  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">项目志录：Memory 用户中心中心开发文档</h1>
            
              <p class="note note-success">
                
                  
                    本文最后更新于：3 年前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><ul>
<li><h5 id="本文档记录了用户中心开发的基本流程，-包含了前期的框架搭建、数据库设计，以及后期的后端接口实现、前端页面开发，实现了基础的登录注册功能，以及查看在线用户状态和删除用户的功能（管理员）"><a href="#本文档记录了用户中心开发的基本流程，-包含了前期的框架搭建、数据库设计，以及后期的后端接口实现、前端页面开发，实现了基础的登录注册功能，以及查看在线用户状态和删除用户的功能（管理员）" class="headerlink" title="本文档记录了用户中心开发的基本流程， 包含了前期的框架搭建、数据库设计，以及后期的后端接口实现、前端页面开发，实现了基础的登录注册功能，以及查看在线用户状态和删除用户的功能（管理员）"></a>本文档记录了用户中心开发的基本流程， 包含了前期的框架搭建、数据库设计，以及后期的后端接口实现、前端页面开发，实现了基础的登录注册功能，以及查看在线用户状态和删除用户的功能（管理员）</h5></li>
</ul>
<h1 id="开发项目前的分析"><a href="#开发项目前的分析" class="headerlink" title="开发项目前的分析"></a>开发项目前的分析</h1><h2 id="企业做项目流程"><a href="#企业做项目流程" class="headerlink" title="企业做项目流程"></a>企业做项目流程</h2><figure class="highlight abnf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs abnf">需求分析 <span class="hljs-operator">=</span>&gt; 设计（概要设计、详细设计）<span class="hljs-operator">=</span>&gt; 技术选型 <span class="hljs-operator">=</span>&gt;<br>初始化 / 引⼊需要的技术 <span class="hljs-operator">=</span>&gt; 写 Demo <span class="hljs-operator">=</span>&gt; 写代码（实现业务逻辑） <span class="hljs-operator">=</span>&gt;<br>测试（单元测试）<span class="hljs-operator">=</span>&gt; 代码提 交 / 代码评审 <span class="hljs-operator">=</span>&gt; 部署<span class="hljs-operator">=</span>&gt; 发布<br></code></pre></td></tr></table></figure>

<h2 id="需求分析"><a href="#需求分析" class="headerlink" title="需求分析"></a>需求分析</h2><ol>
<li>登录 / 注册</li>
<li>⽤户管理（仅管理员可⻅）对⽤户的查询或者修改</li>
<li>⽤户校验（ 仅星球⽤户 ）</li>
</ol>
<h2 id="技术选型"><a href="#技术选型" class="headerlink" title="技术选型"></a>技术选型</h2><h5 id="前端："><a href="#前端：" class="headerlink" title="前端："></a>前端：</h5><p>三件套 + React + 组件库 Ant Design + Umi + Ant Design Pro（现成的管理系统）</p>
<h5 id="后端："><a href="#后端：" class="headerlink" title="后端："></a>后端：</h5><ul>
<li>java</li>
<li>spring（依赖注⼊框架，帮助你管理 Java 对象，集成⼀些其他的内容）</li>
<li>springmvc（web 框架，提供接⼝访问、restful 接⼝等能⼒）</li>
<li>mybatis（Java 操作数据库的框架，持久层框架，对 jdbc 的封装）</li>
<li>mybatis-plus（对 mybatis 的增强，不⽤写 sql 也能实现增删改查）</li>
<li>springboot（快速启动 / 快速集成项⽬。不⽤⾃⼰管理 spring 配置，不⽤⾃⼰整合各种框架）</li>
<li>junit 单元测试库</li>
<li>mysql</li>
</ul>
<h2 id="部署：服务器-容器（平台）"><a href="#部署：服务器-容器（平台）" class="headerlink" title="部署：服务器 / 容器（平台）"></a>部署：服务器 / 容器（平台）</h2><h1 id="框架搭建"><a href="#框架搭建" class="headerlink" title="框架搭建"></a>框架搭建</h1><h3 id="前端框架搭建"><a href="#前端框架搭建" class="headerlink" title="前端框架搭建"></a>前端框架搭建</h3><h5 id="搭建-AntDesignPro-脚手架"><a href="#搭建-AntDesignPro-脚手架" class="headerlink" title="搭建 AntDesignPro 脚手架"></a><a target="_blank" rel="noopener" href="https://blog.csdn.net/Lcq_best/article/details/125569667">搭建 AntDesignPro 脚手架</a></h5><h3 id="后端框架搭建"><a href="#后端框架搭建" class="headerlink" title="后端框架搭建"></a>后端框架搭建</h3><h1 id="数据库设计"><a href="#数据库设计" class="headerlink" title="数据库设计"></a>数据库设计</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs java">create table <span class="hljs-title function_">user</span><br><span class="hljs-params">(</span><br><span class="hljs-params">    id            bigint                                 not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;id&#x27;</span> primary key,</span><br><span class="hljs-params">    user_account  varchar(<span class="hljs-number">256</span>)</span>                           <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;账号&#x27;</span>,<br>    username      <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">256</span>)</span>                           <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;昵称&#x27;</span>,<br>    user_password <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">128</span>)</span>                           not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;密码&#x27;</span>,<br>    avatar_url    <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">512</span>)</span>                           <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;头像&#x27;</span>,<br>    gender        <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">128</span>)</span> <span class="hljs-keyword">default</span> <span class="hljs-string">&#x27;0&#x27;</span>               <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;邮箱&#x27;</span>,<br>    phone         <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">128</span>)</span>                           <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;电话&#x27;</span>,<br>    email         <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">128</span>)</span>                           <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;邮箱&#x27;</span>,<br>    user_status   <span class="hljs-type">int</span>          <span class="hljs-keyword">default</span> <span class="hljs-number">0</span>                 not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;状态 0 - 正常&#x27;</span>,<br>    create_time   datetime     <span class="hljs-keyword">default</span> CURRENT_TIMESTAMP not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;创建时间&#x27;</span>,<br>    update_time   datetime     <span class="hljs-keyword">default</span> CURRENT_TIMESTAMP not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;更新时间&#x27;</span>,<br>    is_delete     tinyint      <span class="hljs-keyword">default</span> <span class="hljs-number">0</span>                 <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;是否删除 0 - 正常&#x27;</span>,<br>    user_role     <span class="hljs-title function_">int</span><span class="hljs-params">(<span class="hljs-number">1</span>)</span>       <span class="hljs-keyword">default</span> <span class="hljs-number">0</span>                 not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;用户权限 0 - 管理员 1 - 普通用户&#x27;</span>,<br>    planet_code   <span class="hljs-title function_">varchar</span><span class="hljs-params">(<span class="hljs-number">512</span>)</span>                           not <span class="hljs-literal">null</span> comment <span class="hljs-string">&#x27;星球编号&#x27;</span><br>)<br>    comment <span class="hljs-string">&#x27;用户&#x27;</span>;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="MybatisX-插件快速生成-domain-entity-service-以及-serviceImpl"><a href="#MybatisX-插件快速生成-domain-entity-service-以及-serviceImpl" class="headerlink" title="MybatisX 插件快速生成 domain entity service 以及 serviceImpl"></a>MybatisX 插件快速生成 domain entity service 以及 serviceImpl</h5><ul>
<li>选择生成目录</li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230324211359229.png" alt="image-20230324211359229"></p>
<ul>
<li>生成选项</li>
</ul>
<p><img src="C:\Users\Lenovo\AppData\Roaming\Typora\typora-user-images\image-20230324211329077.png" alt="image-20230324211329077"></p>
</li>
<li><h5 id="application-yaml-项目配置文件"><a href="#application-yaml-项目配置文件" class="headerlink" title="application.yaml 项目配置文件"></a>application.yaml 项目配置文件</h5><ul>
<li><h5 id="连接到数据库"><a href="#连接到数据库" class="headerlink" title="连接到数据库"></a>连接到数据库</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"># DataSource Config<br>datasource:<br>  driver-class-name: com.mysql.cj.jdbc.Driver<br>  url: jdbc:mysql:<span class="hljs-comment">//localhost:3306/memory</span><br>  username: root<br>  password: Dw990831<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="项目名称"><a href="#项目名称" class="headerlink" title="项目名称"></a>项目名称</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java">spring:<br>  # Project name<br>  application:<br>    name: user-center<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="项目端口-项目所有-API-路径上下文"><a href="#项目端口-项目所有-API-路径上下文" class="headerlink" title="项目端口 | 项目所有 API 路径上下文"></a>项目端口 | 项目所有 API 路径上下文</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"># 端口<br>server:<br>  port: <span class="hljs-number">8081</span><br>  servlet:<br>    context-path: /api<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="逻辑删除-MybatisPlus-提供"><a href="#逻辑删除-MybatisPlus-提供" class="headerlink" title="逻辑删除(MybatisPlus 提供)"></a>逻辑删除(MybatisPlus 提供)</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"># 逻辑删除<br>mybatis-plus:<br>  global-config:<br>    db-config:<br>      logic-delete-field: isDelete # 全局逻辑删除的实体字段名(since <span class="hljs-number">3.3</span><span class="hljs-number">.0</span>,配置后可以忽略不配置步骤<span class="hljs-number">2</span>)<br>      logic-delete-value: <span class="hljs-number">1</span> # 逻辑已删除值(默认为 <span class="hljs-number">1</span>)<br>      logic-not-delete-value: <span class="hljs-number">0</span> # 逻辑未删除值(默认为 <span class="hljs-number">0</span>)<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="session"><a href="#session" class="headerlink" title="session"></a>session</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java">  # session存活时间 一天<br>session:<br>  timeout: <span class="hljs-number">86640</span><br></code></pre></td></tr></table></figure></li>
</ul>
<h1 id="后端开发"><a href="#后端开发" class="headerlink" title="后端开发"></a>后端开发</h1><h5 id="Service-层"><a href="#Service-层" class="headerlink" title="Service 层"></a>Service 层</h5><h2 id="登录-校验"><a href="#登录-校验" class="headerlink" title="登录+校验"></a>登录+校验</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">User <span class="hljs-title function_">userLogin</span><span class="hljs-params">(String userAccount, String userPassword, HttpServletRequest request)</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs reasonml">@Override<br>public User user<span class="hljs-constructor">Login(String <span class="hljs-params">userAccount</span>, String <span class="hljs-params">userPassword</span>, HttpServletRequest <span class="hljs-params">request</span>)</span> &#123;<br>    <span class="hljs-comment">// 1.校验</span><br>    <span class="hljs-comment">// 1.1.账户, 密码不能为空</span><br>    <span class="hljs-keyword">if</span> (<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">StringUtils</span>.</span></span>is<span class="hljs-constructor">AnyBlank(<span class="hljs-params">userAccount</span>, <span class="hljs-params">userPassword</span>)</span>)<br>        return null;<br><br>    <span class="hljs-comment">// 1.2.账户不小于4位</span><br>    <span class="hljs-keyword">if</span> (userAccount.length<span class="hljs-literal">()</span> &lt; <span class="hljs-number">4</span>)<br>        return null;<br><br>    <span class="hljs-comment">// 1.3.用户密码不小于8位</span><br>    <span class="hljs-keyword">if</span> (userPassword.length<span class="hljs-literal">()</span> &lt; <span class="hljs-number">8</span>)<br>        return null;<br><br>    <span class="hljs-comment">// 1.4.账户不包含特殊字符</span><br>    String pattern = <span class="hljs-string">&quot;.*[\\s`~!@#$%^&amp;*()+=|&#123;&#125;&#x27;:;&#x27;,\\[\\].&lt;&gt;/?~！@#￥%……&amp;*（）——+|&#123;&#125;【】‘；：”“’。，、？\\\\]+.*&quot;</span>;<br>    <span class="hljs-keyword">if</span> (<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">Pattern</span>.</span></span>matches(pattern, userAccount))<br>        return null;<br><br>    <span class="hljs-comment">// 1.5.检验该用户是否注册</span><br>    User user = <span class="hljs-keyword">new</span> <span class="hljs-constructor">User()</span>;<br><br>    user.set<span class="hljs-constructor">UserAccount(<span class="hljs-params">userAccount</span>)</span>;<br><br>    String encryptPassword = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">DigestUtils</span>.</span></span>md5<span class="hljs-constructor">DigestAsHex((SALT + <span class="hljs-params">userPassword</span>)</span>.get<span class="hljs-constructor">Bytes()</span>);<br>    user.set<span class="hljs-constructor">UserPassword(<span class="hljs-params">encryptPassword</span>)</span>;<br><br>    QueryWrapper&lt;User&gt; qw = <span class="hljs-keyword">new</span> QueryWrapper&lt;&gt;<span class="hljs-literal">()</span>;<br>    qw.eq(<span class="hljs-string">&quot;user_account&quot;</span>, userAccount).eq(<span class="hljs-string">&quot;user_password&quot;</span>, encryptPassword);<br>    User one = this.get<span class="hljs-constructor">One(<span class="hljs-params">qw</span>)</span>;<br><br>    <span class="hljs-comment">// 1.5.1.用户未注册(包含了MP自带的逻辑删除校验)</span><br>    <span class="hljs-keyword">if</span> (one<span class="hljs-operator"> == </span>null)<br>        return null;<br><br>    <span class="hljs-comment">// 2.脱敏用户信息</span><br>    User safetyUser = get<span class="hljs-constructor">SafetyUser(<span class="hljs-params">one</span>)</span>;<br><br>    <span class="hljs-comment">// 3.记录用户登录态</span><br>    request.get<span class="hljs-constructor">Session()</span>.set<span class="hljs-constructor">Attribute(USER_LOGIN_STATE, <span class="hljs-params">safetyUser</span>)</span>;<br><br>    <span class="hljs-comment">// 4.返回用户信息</span><br>    return safetyUser;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="注册-校验"><a href="#注册-校验" class="headerlink" title="注册+校验"></a>注册+校验</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-type">long</span> <span class="hljs-title function_">userRegister</span><span class="hljs-params">(String userAccount, String userPassword, String checkPassword)</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 用户注册</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> userAccount   账户</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> userPassword  密码</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> checkPassword 二次密码</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> 用户id</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-type">long</span> <span class="hljs-title function_">userRegister</span><span class="hljs-params">(String userAccount, String userPassword, String checkPassword)</span> &#123;<br>        <span class="hljs-comment">// 1.校验</span><br>        <span class="hljs-comment">// 1.1.账户, 密码, 二次密码不能为空</span><br>        <span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword))<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br>        <span class="hljs-comment">// 1.2.账户不小于4位</span><br>        <span class="hljs-keyword">if</span> (userAccount.length() &lt; <span class="hljs-number">4</span>)<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br>        <span class="hljs-comment">// 1.3.账户不能重复</span><br>        QueryWrapper&lt;User&gt; lqw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;(); <span class="hljs-comment">// LambdaQueryWrapper&lt;User&gt; userLambdaQueryWrapper = new LambdaQueryWrapper&lt;&gt;();</span><br>        lqw.eq(<span class="hljs-string">&quot;user_account&quot;</span>, userAccount); <span class="hljs-comment">// userLambdaQueryWrapper.eq(User::getUserAccount, userAccount);</span><br>        <span class="hljs-type">Long</span> <span class="hljs-variable">count</span> <span class="hljs-operator">=</span> userMapper.selectCount(lqw);   <span class="hljs-comment">// long count = this.count(lqw);</span><br><br>        <span class="hljs-keyword">if</span> (count &gt; <span class="hljs-number">0</span>)<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br>        <span class="hljs-comment">// 1.4.用户密码不小于8位</span><br>        <span class="hljs-keyword">if</span> (userPassword.length() &lt; <span class="hljs-number">8</span>)<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br>        <span class="hljs-comment">// 1.5.账户不包含特殊字符</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">pattern</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;.*[\\s`~!@#$%^&amp;*()+=|&#123;&#125;&#x27;:;&#x27;,\\[\\].&lt;&gt;/?~！@#￥%……&amp;*（）——+|&#123;&#125;【】‘；：”“’。，、？\\\\]+.*&quot;</span>;<br>        <span class="hljs-keyword">if</span> (Pattern.matches(pattern, userAccount))<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br>        <span class="hljs-comment">// 1.6.二次密码与密码相同</span><br>        <span class="hljs-keyword">if</span> (!userPassword.equals(checkPassword))<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br><br>        <span class="hljs-comment">// 2.对密码进行加密</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">encryptPassword</span> <span class="hljs-operator">=</span> DigestUtils.md5DigestAsHex((SALT + userPassword).getBytes());<br><span class="hljs-comment">//        System.out.println(encryptPassword);</span><br><br><br>        <span class="hljs-comment">// 3.向数据库中插入用户数据</span><br>        <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">User</span>();<br>        <span class="hljs-comment">//</span><br>        user.setUserAccount(userAccount);<br>        user.setUserPassword(encryptPassword);<br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">save</span> <span class="hljs-operator">=</span> <span class="hljs-built_in">this</span>.save(user);<br>        <span class="hljs-comment">//插入失败</span><br>        <span class="hljs-keyword">if</span> (!save)<br>            <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br><br>        <span class="hljs-keyword">return</span> user.getId();<br>    &#125;<br></code></pre></td></tr></table></figure>

<h2 id="封装脱敏用户信息"><a href="#封装脱敏用户信息" class="headerlink" title="封装脱敏用户信息"></a>封装脱敏用户信息</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">User <span class="hljs-title function_">getSafetyUser</span><span class="hljs-params">(User originUser)</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 用户信息脱敏</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@param</span> originUser 原始用户</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@return</span> 脱敏后的用户</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">public</span> User <span class="hljs-title function_">getSafetyUser</span><span class="hljs-params">(User originUser)</span> &#123;<br>    <span class="hljs-keyword">if</span> (originUser == <span class="hljs-literal">null</span>)<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br><br>    <span class="hljs-type">User</span> <span class="hljs-variable">safetyUser</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">User</span>();<br>    safetyUser.setId(originUser.getId());<br>    safetyUser.setUserAccount(originUser.getUserAccount());<br>    safetyUser.setUsername(originUser.getUsername());<br>    safetyUser.setAvatarUrl(originUser.getAvatarUrl());<br>    safetyUser.setGender(originUser.getGender());<br>    safetyUser.setPhone(originUser.getPhone());<br>    safetyUser.setEmail(originUser.getEmail());<br>    safetyUser.setUserStatus(originUser.getUserStatus());<br>    safetyUser.setCreateTime(originUser.getCreateTime());<br>    safetyUser.setIsDelete(originUser.getIsDelete());<br>    safetyUser.setUserRole(originUser.getUserRole());<br><br>    <span class="hljs-keyword">return</span> safetyUser;<br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="Controller-层"><a href="#Controller-层" class="headerlink" title="Controller 层"></a>Controller 层</h5><h2 id="登录"><a href="#登录" class="headerlink" title="登录"></a>登录</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 用户登录</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> userLoginRequest 登录信息封装</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> request          request</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> User</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@PostMapping(&quot;/login&quot;)</span><br>    <span class="hljs-keyword">public</span> User <span class="hljs-title function_">userLogin</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> UserLoginRequest userLoginRequest, HttpServletRequest request)</span> &#123;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">userAccount</span> <span class="hljs-operator">=</span> userLoginRequest.getUserAccount();<br>        <span class="hljs-type">String</span> <span class="hljs-variable">userPassword</span> <span class="hljs-operator">=</span> userLoginRequest.getUserPassword();<br>        <span class="hljs-comment">//controller对参数的校验</span><br>        <span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword))<br>            <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br><br>        <span class="hljs-keyword">return</span> userService.userLogin(userAccount, userPassword, request);<br>    &#125;<br></code></pre></td></tr></table></figure>

<h2 id="注册"><a href="#注册" class="headerlink" title="注册"></a>注册</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 用户注册</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@param</span> userRegisterRequest 注册信息封装类</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@return</span> id</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@PostMapping(&quot;/register&quot;)</span><br><span class="hljs-keyword">public</span> Long <span class="hljs-title function_">userRegister</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> UserRegisterRequest userRegisterRequest)</span> &#123;<br>    <span class="hljs-type">String</span> <span class="hljs-variable">userAccount</span> <span class="hljs-operator">=</span> userRegisterRequest.getUserAccount();<br>    <span class="hljs-type">String</span> <span class="hljs-variable">userPassword</span> <span class="hljs-operator">=</span> userRegisterRequest.getUserPassword();<br>    <span class="hljs-type">String</span> <span class="hljs-variable">checkPassword</span> <span class="hljs-operator">=</span> userRegisterRequest.getCheckPassword();<br>    <span class="hljs-comment">//controller对参数的校验</span><br>    <span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword))<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br><br>    <span class="hljs-keyword">return</span> userService.userRegister(userAccount, userPassword, checkPassword);<br>&#125;<br></code></pre></td></tr></table></figure>

<h3 id="查询用户-权限校验"><a href="#查询用户-权限校验" class="headerlink" title="查询用户+权限校验"></a>查询用户+权限校验</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 查询用户</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> username 用户名</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> 查到的用户</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/search&quot;)</span><br>    <span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title function_">userSearch</span><span class="hljs-params">(String username, HttpServletRequest request)</span> &#123;<br>        <span class="hljs-comment">// 1.校验权限</span><br>        <span class="hljs-keyword">if</span> (!isAdmin(request))<br>            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>        <span class="hljs-comment">// 2.判空, 默认查询全部</span><br>        QueryWrapper&lt;User&gt; qw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;();<br>        <span class="hljs-keyword">if</span> (StringUtils.isNotBlank(username))<br>            qw.like(<span class="hljs-string">&quot;username&quot;</span>, username);<br>        <span class="hljs-comment">// 3.查询</span><br>        List&lt;User&gt; userList = userService.list(qw);<br>        <span class="hljs-comment">// 4.返回脱敏的用户信息</span><br>        <span class="hljs-keyword">return</span> userList.stream().map(user -&gt; userService.getSafetyUser(user)).collect(Collectors.toList());<br>    &#125;<br></code></pre></td></tr></table></figure>

<h3 id="删除用户-权限校验"><a href="#删除用户-权限校验" class="headerlink" title="删除用户+权限校验"></a>删除用户+权限校验</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 删除用户</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> id 用户id</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> true/false</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@DeleteMapping(&quot;/delete&quot;)</span><br>    <span class="hljs-keyword">public</span> Boolean <span class="hljs-title function_">userDelete</span><span class="hljs-params">(Long id, HttpServletRequest request)</span> &#123;<br>        <span class="hljs-comment">// 1.校验权限</span><br>        <span class="hljs-keyword">if</span> (!isAdmin(request))<br>            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br><br>        <span class="hljs-keyword">if</span> (id &lt;= <span class="hljs-number">0</span>)<br>            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br><br>        <span class="hljs-comment">// 2.删除用户(只要配置MP的逻辑删除的话, 该删除为逻辑删除)</span><br>        <span class="hljs-keyword">return</span> userService.removeById(id);<br>    &#125;<br><br></code></pre></td></tr></table></figure>

<h2 id="获取用户登录态"><a href="#获取用户登录态" class="headerlink" title="获取用户登录态"></a>获取用户登录态</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 查询用户</span><br><span class="hljs-comment">   *</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> username 用户名</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@return</span> 查到的用户</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-meta">@GetMapping(&quot;/search&quot;)</span><br>  <span class="hljs-keyword">public</span> List&lt;User&gt; <span class="hljs-title function_">userSearch</span><span class="hljs-params">(String username, HttpServletRequest request)</span> &#123;<br>      <span class="hljs-comment">// 1.校验权限</span><br>      <span class="hljs-keyword">if</span> (!isAdmin(request))<br>          <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>      <span class="hljs-comment">// 2.判空, 默认查询全部</span><br>      QueryWrapper&lt;User&gt; qw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;();<br>      <span class="hljs-keyword">if</span> (StringUtils.isNotBlank(username))<br>          qw.like(<span class="hljs-string">&quot;username&quot;</span>, username);<br>      <span class="hljs-comment">// 3.查询</span><br>      List&lt;User&gt; userList = userService.list(qw);<br>      <span class="hljs-comment">// 4.返回脱敏的用户信息</span><br>      <span class="hljs-keyword">return</span> userList.stream().map(user -&gt; userService.getSafetyUser(user)).collect(Collectors.toList());<br>  &#125;<br></code></pre></td></tr></table></figure>

<h2 id="封装校验管理员逻辑"><a href="#封装校验管理员逻辑" class="headerlink" title="封装校验管理员逻辑"></a>封装校验管理员逻辑</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 校验是否为管理员</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> request request</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> 校验成功与否</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">public</span> Boolean <span class="hljs-title function_">isAdmin</span><span class="hljs-params">(HttpServletRequest request)</span> &#123;<br>        <span class="hljs-comment">//校验是否为管理员</span><br>        <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> (User) request.getSession().getAttribute(USER_LOGIN_STATE);<br>        <span class="hljs-keyword">return</span> user != <span class="hljs-literal">null</span> &amp;&amp; user.getUserRole() == ADMIN_ROLE;<br>    &#125;<br></code></pre></td></tr></table></figure>

<h5 id="constant-层"><a href="#constant-层" class="headerlink" title="constant 层"></a>constant 层</h5><h2 id="封装常量"><a href="#封装常量" class="headerlink" title="封装常量"></a>封装常量</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//登录用户session Key</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">USER_LOGIN_STATE</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;userLoginState&quot;</span>;<br>   <span class="hljs-comment">//管理员权限</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> <span class="hljs-variable">ADMIN_ROLE</span> <span class="hljs-operator">=</span> <span class="hljs-number">1</span>;<br>   <span class="hljs-comment">//普通用户权限</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> <span class="hljs-variable">DEFAULT_ROLE</span> <span class="hljs-operator">=</span> <span class="hljs-number">1</span>;<br></code></pre></td></tr></table></figure>

<h5 id="model-request-层"><a href="#model-request-层" class="headerlink" title="model/request 层"></a>model/request 层</h5><h2 id="封装-login-register-实体接收类"><a href="#封装-login-register-实体接收类" class="headerlink" title="封装 login/register 实体接收类"></a>封装 login/register 实体接收类</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Data</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserLoginRequest</span> &#123;<br>    <span class="hljs-keyword">private</span> String userAccount;<br>    <span class="hljs-keyword">private</span> String userPassword;<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Data</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserRegisterRequest</span> &#123;<br>    <span class="hljs-keyword">private</span> String userAccount;<br>    <span class="hljs-keyword">private</span> String userPassword;<br>    <span class="hljs-keyword">private</span> String checkPassword;<br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="前端开发"><a href="#前端开发" class="headerlink" title="前端开发"></a>前端开发</h1><h2 id="修改登录页面"><a href="#修改登录页面" class="headerlink" title="修改登录页面"></a>修改登录页面</h2><ul>
<li><p>熟悉登录流程 请求地址 返回数据</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 登录</span><br><span class="hljs-keyword">const</span> user = <span class="hljs-keyword">await</span> <span class="hljs-title function_">login</span>(&#123;<br>  ...values,<br>  <span class="hljs-keyword">type</span>,<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/** 登录接口 POST /api/login/account */</span><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">login</span>(<span class="hljs-params"></span><br><span class="hljs-params">  body: API.LoginParams,</span><br><span class="hljs-params">  options?: &#123; [key: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> &#125;</span><br><span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">LoginResult</span>&gt;(<span class="hljs-string">&quot;/api/user/login&quot;</span>, &#123;<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>    <span class="hljs-attr">headers</span>: &#123;<br>      <span class="hljs-string">&quot;Content-Type&quot;</span>: <span class="hljs-string">&quot;application/json&quot;</span>,<br>    &#125;,<br>    <span class="hljs-attr">data</span>: body,<br>    ...(options || &#123;&#125;),<br>  &#125;);<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>登录表单的校验逻辑(账号 密码)</p>
</li>
<li><p>登录校验 成功则提示登录成功 重定向到 welcome 页面</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-comment">// 登录成功</span><br><span class="hljs-keyword">if</span> (user) &#123;<br>  <span class="hljs-keyword">const</span> defaultLoginSuccessMessage = <span class="hljs-string">&#x27;登录成功！&#x27;</span>;<br>  message.<span class="hljs-title function_">success</span>(defaultLoginSuccessMessage);<br>  <span class="hljs-keyword">await</span> <span class="hljs-title function_">fetchUserInfo</span>();<br>  <span class="hljs-comment">/** 此方法会跳转到 redirect 参数所在的位置 */</span><br>  <span class="hljs-keyword">if</span> (!history) <span class="hljs-keyword">return</span>;<br>  <span class="hljs-keyword">const</span> &#123;query&#125; = history.<span class="hljs-property">location</span>;<br>  <span class="hljs-keyword">const</span> &#123;redirect&#125; = query <span class="hljs-keyword">as</span> &#123;<br>    <span class="hljs-attr">redirect</span>: string;<br>  &#125;;<br>  <span class="hljs-comment">// &#123; path: &#x27;/&#x27;, redirect: &#x27;/welcome&#x27; &#125;,</span><br>  <span class="hljs-comment">// 跳转到欢迎页面</span><br>  history.<span class="hljs-title function_">push</span>(redirect || <span class="hljs-string">&#x27;/&#x27;</span>);<br>  <span class="hljs-keyword">return</span>;<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>登录校验 失败则提示登录失败</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">const</span> defaultLoginFailureMessage = <span class="hljs-string">&quot;登录失败，请重试！&quot;</span>;<br>message.<span class="hljs-title function_">error</span>(defaultLoginFailureMessage);<br></code></pre></td></tr></table></figure></li>
</ul>
<h2 id="开发注册页面"><a href="#开发注册页面" class="headerlink" title="开发注册页面"></a>开发注册页面</h2><ul>
<li><p>登录页的复制粘贴</p>
</li>
<li><p>路由的理解 设置注册页的路由</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123; <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;注册&#x27;</span>, <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/user/register&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./user/Register&#x27;</span> &#125;,<br></code></pre></td></tr></table></figure></li>
<li><p>注册表单的校验逻辑(账号 密码)</p>
</li>
<li><p>熟悉注册流程 请求地址 返回数据</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 发起请求</span><br><span class="hljs-keyword">const</span> id = <span class="hljs-keyword">await</span> <span class="hljs-title function_">register</span>(&#123;<br>  ...values,<br>  <span class="hljs-keyword">type</span>,<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/** 注册接口 POST /api/login/account */</span><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">register</span>(<span class="hljs-params"></span><br><span class="hljs-params">  body: API.LoginParams,</span><br><span class="hljs-params">  options?: &#123; [key: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> &#125;</span><br><span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">LoginResult</span>&gt;(<span class="hljs-string">&quot;/api/user/register&quot;</span>, &#123;<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>    <span class="hljs-attr">headers</span>: &#123;<br>      <span class="hljs-string">&quot;Content-Type&quot;</span>: <span class="hljs-string">&quot;application/json&quot;</span>,<br>    &#125;,<br>    <span class="hljs-attr">data</span>: body,<br>    ...(options || &#123;&#125;),<br>  &#125;);<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>解决访问注册页面 重定向到 Login 问题 业务逻辑 白名单内, 无需重定向到登录页</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">//白名单内无需重定向</span><br><span class="hljs-keyword">if</span> (<span class="hljs-variable constant_">NO_NEED_LOGIN_WHITE_LIST</span>.<span class="hljs-title function_">includes</span>(location.<span class="hljs-property">pathname</span>)) <span class="hljs-keyword">return</span>;<br><span class="hljs-comment">// 白名单外, 如果没有登录, 重定向到 login</span><br><span class="hljs-keyword">if</span> (!initialState?.<span class="hljs-property">currentUser</span>) &#123;<br>  history.<span class="hljs-title function_">push</span>(loginPath);<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>注册成功 提示”注册成功” 跳转登录页面</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs typescript">history.<span class="hljs-title function_">push</span>(&#123;<br>  <span class="hljs-attr">pathname</span>: <span class="hljs-string">&quot;user/login&quot;</span>,<br>  query,<br>&#125;);<br>跳转到登录页面;<br></code></pre></td></tr></table></figure></li>
<li><p>注册失败 提示”注册失败”</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">const</span> defaultLoginFailureMessage = <span class="hljs-string">&quot;注册失败，请重试！&quot;</span>;<br>message.<span class="hljs-title function_">error</span>(defaultLoginFailureMessage);<br></code></pre></td></tr></table></figure></li>
<li><p>“登录” 修改为 “注册” (了解源码)</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs typescript">submitter=&#123;&#123;<br>  <span class="hljs-attr">searchConfig</span>: &#123;<br>    <span class="hljs-attr">submitText</span>: <span class="hljs-string">&#x27;注册&#x27;</span><br>  &#125;<br>&#125;&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>添加注册校验 简单的逻辑 根据返回的数据 解构出密码和二次密码 判断二者是否相等</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">const</span> &#123; userPassword, checkPassword &#125; = values;<br><span class="hljs-comment">//校验</span><br><span class="hljs-keyword">if</span> (userPassword != checkPassword) &#123;<br>  message.<span class="hljs-title function_">error</span>(<span class="hljs-string">&quot;两次输入的密码不一致!&quot;</span>);<br>  <span class="hljs-keyword">return</span>;<br>&#125;<br></code></pre></td></tr></table></figure></li>
<li><p>添加登录页跳转到注册页的链接”新用户注册” 仿照 “忘记密码”</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;a href=&quot;/user/register&quot; target=&quot;_blank&quot; rel=&quot;noreferrer&quot;&gt;<br>  新用户注册<br>&lt;/a&gt;<br></code></pre></td></tr></table></figure></li>
</ul>
<h1 id="获取当前用户登录态"><a href="#获取当前用户登录态" class="headerlink" title="获取当前用户登录态"></a>获取当前用户登录态</h1><h2 id="后端实现接口"><a href="#后端实现接口" class="headerlink" title="后端实现接口"></a>后端实现接口</h2><p>返回当前用户的当前信息(重新查询过数据库)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@GetMapping(&quot;/currentUser&quot;)</span><br><span class="hljs-keyword">public</span> User <span class="hljs-title function_">getCurrentUser</span><span class="hljs-params">(HttpServletRequest request)</span> &#123;<br>    <span class="hljs-type">User</span> <span class="hljs-variable">currentUser</span> <span class="hljs-operator">=</span> (User) request.getSession().getAttribute(USER_LOGIN_STATE);<br>    <span class="hljs-keyword">if</span> (currentUser == <span class="hljs-literal">null</span>)<br>        <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br><br>    <span class="hljs-type">Long</span> <span class="hljs-variable">id</span> <span class="hljs-operator">=</span> currentUser.getId();<br>    <span class="hljs-comment">// 查询数据库, 获取最新信息, 而非登录时记录的信息</span><br>    <span class="hljs-keyword">return</span> userService.getById(id);<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="前端获取用户登录态"><a href="#前端获取用户登录态" class="headerlink" title="前端获取用户登录态"></a>前端获取用户登录态</h2><ul>
<li>app.tsx 前端服务入口 每次打开页面, 都会执行查询</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 查询用户登录态信息</span><br><span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> <span class="hljs-title function_">queryCurrentUser</span>();<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 请求</span><br><span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;(<span class="hljs-string">&quot;/api/user/currentUser&quot;</span>, &#123;<br>  <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;GET&quot;</span>,<br>  ...(options || &#123;&#125;),<br>&#125;);<br></code></pre></td></tr></table></figure>

<ul>
<li>修改 CurrentUser, 将返回的字段全部修改为对应数据库中的字段</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">type</span> <span class="hljs-title class_">CurrentUser</span> = &#123;<br>  id?: <span class="hljs-built_in">number</span>;<br>  userAccount?: <span class="hljs-built_in">string</span>;<br>  username?: <span class="hljs-built_in">string</span>;<br>  avatarUtil?: <span class="hljs-built_in">string</span>;<br>  gender?: <span class="hljs-built_in">string</span>;<br>  phone?: <span class="hljs-built_in">string</span>;<br>  email?: <span class="hljs-built_in">string</span>;<br>  userStatus?: <span class="hljs-built_in">string</span>;<br>  userRole?: <span class="hljs-built_in">string</span>;<br>&#125;;<br></code></pre></td></tr></table></figure>

<ul>
<li>设置白名单, 登录注册页面不会返回查询到的用户登录态, 其余页面会返回查询到的用户登录态</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 白名单内(登陆注册), 不返回用户登录态信息</span><br><span class="hljs-keyword">if</span> (<span class="hljs-variable constant_">NO_NEED_LOGIN_WHITE_LIST</span>.<span class="hljs-title function_">includes</span>(history.<span class="hljs-property">location</span>.<span class="hljs-property">pathname</span>)) &#123;<br>  <span class="hljs-keyword">return</span> &#123;<br>    fetchUserInfo,<br>    <span class="hljs-attr">settings</span>: defaultSettings,<br>  &#125;;<br>&#125;<br><span class="hljs-comment">// 登陆注册后, 页面返回用户登录态信息</span><br><span class="hljs-keyword">const</span> currentUser = <span class="hljs-keyword">await</span> <span class="hljs-title function_">fetchUserInfo</span>();<br><span class="hljs-keyword">return</span> &#123;<br>  fetchUserInfo,<br>  currentUser,<br>  <span class="hljs-attr">settings</span>: defaultSettings,<br>&#125;;<br></code></pre></td></tr></table></figure>

<h1 id="开发欢迎页面"><a href="#开发欢迎页面" class="headerlink" title="开发欢迎页面"></a>开发欢迎页面</h1><ul>
<li>设置欢迎页面的水印 头像</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-attr">waterMarkProps</span>: &#123;<br>  <span class="hljs-comment">// 添加水印</span><br>  <span class="hljs-attr">content</span>: initialState?.<span class="hljs-property">currentUser</span>?.<span class="hljs-property">username</span>, <span class="hljs-comment">// 以用户昵称作为水印</span><br>&#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li>头像的话在/src/components/RightContext/AvatarDropdown.tsx 里有个引用</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;Avatar<br>  size=&quot;small&quot;<br>  className=&quot;&#123;styles.avatar&#125;&quot;<br>  src=&quot;&#123;currentUser.avatarUrl&#125;&quot;<br>  alt=&quot;avatar&quot;<br>/&gt;<br></code></pre></td></tr></table></figure>

<ul>
<li>我这边头像刷新不出来是因为数据库里字段名写成 avatarUtil 了,一直没发现,改了正确的字段名以及映射实体类属性名 Mapper.xml 文件后 头像映射正常了</li>
</ul>
<h1 id="开发用户管理页面"><a href="#开发用户管理页面" class="headerlink" title="开发用户管理页面"></a>开发用户管理页面</h1><h2 id="新建一个管理界面"><a href="#新建一个管理界面" class="headerlink" title="新建一个管理界面"></a>新建一个管理界面</h2><ul>
<li><p>他奶奶的我这边出问题了</p>
</li>
<li><p>我新建了一个/Pages/Admin/UserManage 把 Register 文件夹复制过去打算修改, 结果它给我把 Register 的路由给替换了</p>
</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123; <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;注册&#x27;</span>, <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/user/register&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./user/UserManage&#x27;</span> &#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li>然后前端直接挂掉了, 报错报了这个玩意儿 妈的找了半天 终于发现了 把路由改回来了</li>
</ul>
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs lua">Cannot <span class="hljs-built_in">find</span> <span class="hljs-built_in">module</span> <span class="hljs-string">&#x27;D:/Project/星球项目/ClientCenter/myapp/src/pages/user/UserManage&#x27;</span><br></code></pre></td></tr></table></figure>

<ul>
<li>给新增的用户管理页面加个路由</li>
</ul>
<p> path: ‘/admin/user-manager’ 是访问路径</p>
<p> component: ‘./Admin/UserManage’ 是资源路径</p>
<p> 仿照下面的写就行了</p>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123;<br>  <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin&#x27;</span>,<br>  <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;管理页&#x27;</span>,<br>  <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;crown&#x27;</span>,<br>  <span class="hljs-attr">access</span>: <span class="hljs-string">&#x27;canAdmin&#x27;</span>,<br>  <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Admin&#x27;</span>,<br>  <span class="hljs-attr">routes</span>: [<br>  <span class="hljs-comment">// 用户管理</span><br>    &#123; <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin/user-manager&#x27;</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;用户管理&#x27;</span>, <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;smile&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Admin/UserManage&#x27;</span> &#125;,<br>    &#123; <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin/sub-page&#x27;</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;二级管理页&#x27;</span>, <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;smile&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Welcome&#x27;</span> &#125;,<br>    &#123; <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./404&#x27;</span> &#125;,<br>  ],<br>&#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li>访问 <a target="_blank" rel="noopener" href="http://localhost:8000/admin/user-manager">http://localhost:8000/admin/user-manager</a> 发现无权访问 好像存在访问权限 访问不到</li>
</ul>
<h4 id="项目全局入口"><a href="#项目全局入口" class="headerlink" title="项目全局入口"></a>项目全局入口</h4><h6 id="app-tsx-是项目全局入口-里面包含了访问页面时-就会调用的方法-重定向到-Login-页-查询用户登录态"><a href="#app-tsx-是项目全局入口-里面包含了访问页面时-就会调用的方法-重定向到-Login-页-查询用户登录态" class="headerlink" title="app.tsx 是项目全局入口 里面包含了访问页面时, 就会调用的方法, 重定向到 Login 页 查询用户登录态"></a>app.tsx 是项目全局入口 里面包含了访问页面时, 就会调用的方法, <strong>重定向到 Login 页 查询用户登录态</strong></h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123;<br>  <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin&#x27;</span>,<br>  <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;管理页&#x27;</span>,<br>  <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;crown&#x27;</span>,<br>  <span class="hljs-comment">// 管理员权限校验</span><br>  <span class="hljs-attr">access</span>: <span class="hljs-string">&#x27;canAdmin&#x27;</span>,<br>  <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Admin&#x27;</span>,<br>  <span class="hljs-attr">routes</span>: [<br>    &#123; <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin/user-manager&#x27;</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;用户管理&#x27;</span>, <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;smile&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Admin/UserManage&#x27;</span> &#125;,<br>    &#123; <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin/sub-page&#x27;</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;二级管理页&#x27;</span>, <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;smile&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Welcome&#x27;</span> &#125;,<br>    &#123; <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./404&#x27;</span> &#125;,<br>  ],<br>&#125;,<br></code></pre></td></tr></table></figure>

<h6 id="看到那个-access-了吗-通过校验’canAdmin’的真假-判断是否具有管理员权限-这就是控制了这个路由的访问权限-怎么实现的"><a href="#看到那个-access-了吗-通过校验’canAdmin’的真假-判断是否具有管理员权限-这就是控制了这个路由的访问权限-怎么实现的" class="headerlink" title="看到那个 access 了吗 通过校验’canAdmin’的真假 判断是否具有管理员权限 这就是控制了这个路由的访问权限 怎么实现的?"></a>看到那个 access 了吗 通过校验’canAdmin’的真假 判断是否具有管理员权限 这就是控制了这个路由的访问权限 怎么实现的?</h6><h4 id="访问权限管理"><a href="#访问权限管理" class="headerlink" title="访问权限管理"></a>访问权限管理</h4><h6 id="access-ts-是访问权限管理-在查询到用户登录态后-通过返回结果-CurrentUser-来校验-这段逻辑非常简单-我们可以修改为自己的逻辑"><a href="#access-ts-是访问权限管理-在查询到用户登录态后-通过返回结果-CurrentUser-来校验-这段逻辑非常简单-我们可以修改为自己的逻辑" class="headerlink" title="access.ts 是访问权限管理 在查询到用户登录态后 通过返回结果 CurrentUser 来校验 这段逻辑非常简单 我们可以修改为自己的逻辑"></a>access.ts 是访问权限管理 在查询到用户登录态后 通过返回结果 CurrentUser 来校验 这段逻辑非常简单 我们可以修改为自己的逻辑</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">access</span>(<span class="hljs-params"></span><br><span class="hljs-params">  initialState: &#123; currentUser?: API.CurrentUser &#125; | <span class="hljs-literal">undefined</span></span><br><span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">const</span> &#123; currentUser &#125; = initialState ?? &#123;&#125;;<br>  <span class="hljs-comment">// 权限校验</span><br>  <span class="hljs-keyword">return</span> &#123;<br>    <span class="hljs-comment">// 校验管理员权限</span><br>    <span class="hljs-attr">canAdmin</span>: currentUser &amp;&amp; currentUser.<span class="hljs-property">access</span> === <span class="hljs-string">&quot;admin&quot;</span>,<br>  &#125;;<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>修改访问路由的管理员权限的校验规则</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 校验管理员权限</span><br><span class="hljs-attr">canAdmin</span>: currentUser &amp;&amp; currentUser.<span class="hljs-property">userRole</span> === <span class="hljs-number">1</span>,<br></code></pre></td></tr></table></figure>

<ul>
<li>找一个管理员账号登录, 发现 <a target="_blank" rel="noopener" href="http://localhost:8000/admin/user-manager">http://localhost:8000/admin/user-manager</a> 页面可以访问了 因为我们由管理员权限了</li>
</ul>
<h2 id="正确显示管理页面"><a href="#正确显示管理页面" class="headerlink" title="正确显示管理页面"></a>正确显示管理页面</h2><h6 id="原本的页面显示组件是-Admin-tsx"><a href="#原本的页面显示组件是-Admin-tsx" class="headerlink" title="原本的页面显示组件是 Admin.tsx"></a>原本的页面显示组件是 Admin.tsx</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 父路由</span><br><span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin&#x27;</span>,<br><span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;管理页&#x27;</span>,<br><span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;crown&#x27;</span>,<br><span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Admin&#x27;</span>,<br>	<span class="hljs-comment">// 子路由</span><br>    <span class="hljs-attr">routes</span>: [<br>      &#123; <span class="hljs-attr">path</span>: <span class="hljs-string">&#x27;/admin/user-manager&#x27;</span>, <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;用户管理&#x27;</span>, <span class="hljs-attr">icon</span>: <span class="hljs-string">&#x27;smile&#x27;</span>, <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./Admin/UserManage&#x27;</span> &#125;,<br>      &#123; <span class="hljs-attr">component</span>: <span class="hljs-string">&#x27;./404&#x27;</span> &#125;,<br>    ],<br></code></pre></td></tr></table></figure>

<h6 id="组件里面这么写"><a href="#组件里面这么写" class="headerlink" title="组件里面这么写:"></a>组件里面这么写:</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs typescript">onst <span class="hljs-title class_">Admin</span>: <span class="hljs-title class_">React</span>.<span class="hljs-property">FC</span> = <span class="hljs-function">(<span class="hljs-params">&#123;children&#125;</span>) =&gt;</span> &#123;<br>  <span class="hljs-keyword">return</span> (<br>    <span class="language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">PageHeaderWrapper</span> <span class="hljs-attr">content</span>=<span class="hljs-string">&#123;</span>&#x27; <span class="hljs-attr">这个页面只有</span> <span class="hljs-attr">admin</span> <span class="hljs-attr">权限才能查看</span>&#x27;&#125;&gt;</span></span><br><span class="language-xml">    // 展示子路由组件</span><br><span class="language-xml">      &#123;children&#125;</span><br><span class="language-xml">    <span class="hljs-tag">&lt;/<span class="hljs-name">PageHeaderWrapper</span>&gt;</span></span><br>  );<br>&#125;;<br></code></pre></td></tr></table></figure>

<h6 id="这样管理页面就能显示我们定义的组件-Admin-UserManage-index-tsx-了"><a href="#这样管理页面就能显示我们定义的组件-Admin-UserManage-index-tsx-了" class="headerlink" title="这样管理页面就能显示我们定义的组件 Admin/UserManage/index.tsx 了"></a>这样管理页面就能显示我们定义的组件 Admin/UserManage/index.tsx 了</h6><ul>
<li><p>我们上 ProComponents 的高级表格里找一个高级表格, 作为管理页面</p>
</li>
<li><p>直接找一个漂亮有用的, 粘贴到/UserManage/index.tsx 里</p>
</li>
<li><p>接下来就是对该页面的改造了</p>
</li>
</ul>
<h2 id="改造新的组件-管理页面"><a href="#改造新的组件-管理页面" class="headerlink" title="改造新的组件(管理页面)"></a>改造新的组件(管理页面)</h2><h4 id="改造表格数据-数据如何展示"><a href="#改造表格数据-数据如何展示" class="headerlink" title="改造表格数据(数据如何展示)"></a>改造表格数据(数据如何展示)</h4><ul>
<li>改造返回数据类型 (API.CurrentUser) 和各列名</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 返回的数据类型改造为Api.currentUser</span><br><span class="hljs-keyword">const</span> <span class="hljs-attr">columns</span>: <span class="hljs-title class_">ProColumns</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;[] = [<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;账号&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;userAccount&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;昵称&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;username&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;头像&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;avatarUrl&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;性别&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;gender&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;电话&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;phone&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;邮件&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;email&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;角色&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;userRole&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;创建时间&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;createTime&quot;</span>,<br>    <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>  &#125;,<br>  &#123;<br>    <span class="hljs-attr">disable</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-attr">title</span>: <span class="hljs-string">&quot;状态&quot;</span>,<br>    <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&quot;state&quot;</span>,<br>    <span class="hljs-attr">filters</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-attr">onFilter</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-attr">ellipsis</span>: <span class="hljs-literal">true</span>,<br>    <span class="hljs-attr">valueType</span>: <span class="hljs-string">&quot;select&quot;</span>,<br>    <span class="hljs-attr">valueEnum</span>: &#123;<br>      <span class="hljs-attr">all</span>: &#123; <span class="hljs-attr">text</span>: <span class="hljs-string">&quot;超长&quot;</span>.<span class="hljs-title function_">repeat</span>(<span class="hljs-number">50</span>) &#125;,<br>      <span class="hljs-attr">open</span>: &#123;<br>        <span class="hljs-attr">text</span>: <span class="hljs-string">&quot;未解决&quot;</span>,<br>        <span class="hljs-attr">status</span>: <span class="hljs-string">&quot;Error&quot;</span>,<br>      &#125;,<br>      <span class="hljs-attr">closed</span>: &#123;<br>        <span class="hljs-attr">text</span>: <span class="hljs-string">&quot;已解决&quot;</span>,<br>        <span class="hljs-attr">status</span>: <span class="hljs-string">&quot;Success&quot;</span>,<br>        <span class="hljs-attr">disabled</span>: <span class="hljs-literal">true</span>,<br>      &#125;,<br>      <span class="hljs-attr">processing</span>: &#123;<br>        <span class="hljs-attr">text</span>: <span class="hljs-string">&quot;解决中&quot;</span>,<br>        <span class="hljs-attr">status</span>: <span class="hljs-string">&quot;Processing&quot;</span>,<br>      &#125;,<br>    &#125;,<br>  &#125;,<br>];<br></code></pre></td></tr></table></figure>

<h4 id="改造访问路径-数据从何而来"><a href="#改造访问路径-数据从何而来" class="headerlink" title="改造访问路径(数据从何而来)"></a>改造访问路径(数据从何而来)</h4><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs typescript">columns=&#123;columns&#125;<br>actionRef=&#123;actionRef&#125;<br>cardBordered<br>request=&#123;<span class="hljs-keyword">async</span> (params = &#123;&#125;, sort, filter) =&gt; &#123;<br>  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(sort, filter);<br>  <span class="hljs-comment">// 返回userList</span><br>  <span class="hljs-comment">// 自定义函数</span><br>  <span class="hljs-keyword">const</span> userList = <span class="hljs-keyword">await</span> <span class="hljs-title function_">searchUsers</span>();<br>  <span class="hljs-keyword">return</span> &#123;<br>    <span class="hljs-attr">data</span>: userList<br>  &#125;<br>&#125;&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>在 api.ts 下编写自定义函数 searchUsers, 并设置访问路径</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/** 此处后端没有提供注释 GET /api/notices */</span><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">searchUsers</span>(<span class="hljs-params">options?: &#123; [key: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> &#125;</span>) &#123;<br>  <span class="hljs-comment">// 返回数据格式为API.CurrentUser</span><br>  <span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;(<span class="hljs-string">&quot;/api/user/search&quot;</span>, &#123;<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;GET&quot;</span>,<br>    ...(options || &#123;&#125;),<br>  &#125;);<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>后端返回所有用户数据, 并展示在表格中 展示成功了</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 查询用户</span><br><span class="hljs-comment"> *</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@param</span> username 用户名</span><br><span class="hljs-comment"> * <span class="hljs-doctag">@return</span> 查到的用户</span><br><span class="hljs-comment"> */</span><br><span class="hljs-meta">@GetMapping</span>(<span class="hljs-string">&quot;/search&quot;</span>)<br><span class="hljs-keyword">public</span> <span class="hljs-title class_">List</span>&lt;<span class="hljs-title class_">User</span>&gt; <span class="hljs-title function_">userSearch</span>(<span class="hljs-params"><span class="hljs-built_in">String</span> username, HttpServletRequest request</span>) &#123;<br>    <span class="hljs-comment">// 1.校验权限</span><br>    <span class="hljs-keyword">if</span> (!<span class="hljs-title function_">isAdmin</span>(request))<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>    <span class="hljs-comment">// 2.判空, 默认查询全部</span><br>    <span class="hljs-title class_">QueryWrapper</span>&lt;<span class="hljs-title class_">User</span>&gt; qw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;();<br>    <span class="hljs-keyword">if</span> (<span class="hljs-title class_">StringUtils</span>.<span class="hljs-title function_">isNotBlank</span>(username))<br>        qw.<span class="hljs-title function_">like</span>(<span class="hljs-string">&quot;username&quot;</span>, username);<br>    <span class="hljs-comment">// 3.查询</span><br>    <span class="hljs-title class_">List</span>&lt;<span class="hljs-title class_">User</span>&gt; userList = userService.<span class="hljs-title function_">list</span>(qw);<br>    <span class="hljs-comment">// 4.返回脱敏的用户信息</span><br>    <span class="hljs-keyword">return</span> userList.<span class="hljs-title function_">stream</span>().<span class="hljs-title function_">map</span>(user -&gt; userService.<span class="hljs-title function_">getSafetyUser</span>(user)).<span class="hljs-title function_">collect</span>(<span class="hljs-title class_">Collectors</span>.<span class="hljs-title function_">toList</span>());<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="项目全局命名空间-把一组-TS-类型全部定义到了这个命名空间下-即定义了一组返回数据对象-取的时候就不需要-import-了-直接-API-TS-类型就可以取到"><a href="#项目全局命名空间-把一组-TS-类型全部定义到了这个命名空间下-即定义了一组返回数据对象-取的时候就不需要-import-了-直接-API-TS-类型就可以取到" class="headerlink" title="项目全局命名空间, 把一组 TS 类型全部定义到了这个命名空间下, 即定义了一组返回数据对象, 取的时候就不需要 import 了, 直接 API.TS 类型就可以取到"></a><strong><em>项目全局命名空间</em></strong>, <em>把一组 TS 类型全部定义到了这个命名空间下, 即定义了一组返回数据对象, 取的时候就不需要 import 了, 直接 API.TS 类型就可以取到</em></h6><h6 id="src-services-ant-design-pro-typings-d-ts"><a href="#src-services-ant-design-pro-typings-d-ts" class="headerlink" title="src/services/ant-design-pro/typings.d.ts"></a>src/services/ant-design-pro/typings.d.ts</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> API &#123;<br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">CurrentUser</span> = &#123;<br>  .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">LoginResult</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">RegisterResult</span> = <span class="hljs-built_in">number</span>;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">PageParams</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">RuleListItem</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">RuleList</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">FakeCaptcha</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">LoginParams</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">RegisterParams</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">ErrorResponse</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">NoticeIconList</span> = &#123;<br>   .............<br>  &#125;;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">NoticeIconItemType</span> = <span class="hljs-string">&#x27;notification&#x27;</span> | <span class="hljs-string">&#x27;message&#x27;</span> | <span class="hljs-string">&#x27;event&#x27;</span>;<br><br>  <span class="hljs-keyword">type</span> <span class="hljs-title class_">NoticeIconItem</span> = &#123;<br>   .............<br>  &#125;;<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="src-services-ant-design-pro-api-ts-这里定义了许多请求接口-根据请求地址-请求方式发出请求"><a href="#src-services-ant-design-pro-api-ts-这里定义了许多请求接口-根据请求地址-请求方式发出请求" class="headerlink" title="src/services/ant-design-pro/api.ts 这里定义了许多请求接口 根据请求地址 请求方式发出请求"></a>src/services/ant-design-pro/api.ts <em>这里定义了许多请求接口</em> <em>根据请求地址</em> 请求方式发出请求</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">import</span> &#123; request &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;umi&quot;</span>;<br></code></pre></td></tr></table></figure>

<h2 id="修改表格显示细节"><a href="#修改表格显示细节" class="headerlink" title="修改表格显示细节"></a>修改表格显示细节</h2><ul>
<li><p>通过 columns 定义表格有哪些列</p>
</li>
<li><p>column 属性</p>
</li>
</ul>
<p> <strong><em>dataIndex 对应返回数据对象的属性</em></strong></p>
<p> <strong><em>title 表格列名</em></strong></p>
<p> <strong><em>copyable 是否允许复制</em></strong></p>
<p> <strong><em>ellipsis 是否允许缩略</em></strong></p>
<p> <strong><em>valueType 用于声明这一列的类型</em></strong></p>
<ul>
<li>头像</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs vue">&#123; title: &#x27;头像&#x27;, dataIndex: &#x27;avatarUrl&#x27;, copyable: true, render: (_, record) =&gt;<br>(<br>&lt;div&gt;<br>      &lt;img src=&#123;record.avatarUrl&#125; width=&#123;100&#125;/&gt;<br>    &lt;/div&gt;<br>) &#125;,<br></code></pre></td></tr></table></figure>

<ul>
<li>性别 角色 状态</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123;<br>  <span class="hljs-attr">title</span>: <span class="hljs-string">&#x27;性别&#x27;</span>,<br>  <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&#x27;gender&#x27;</span>,<br>  <span class="hljs-attr">valueType</span>: <span class="hljs-string">&#x27;select&#x27;</span>,<br>  <span class="hljs-attr">valueEnum</span>: &#123;<br>    <span class="hljs-number">0</span>: &#123;<br>      <span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;女&#x27;</span>,<br>    &#125;,<br>    <span class="hljs-number">1</span>: &#123;<br>      <span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;男&#x27;</span>,<br>    &#125;,<br>  &#125;,<br>&#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123;<br>  <span class="hljs-attr">title</span>: <span class="hljs-string">&#x27;角色&#x27;</span>,<br>  <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&#x27;userRole&#x27;</span>,<br>  <span class="hljs-attr">valueType</span>: <span class="hljs-string">&#x27;select&#x27;</span>,<br>  <span class="hljs-attr">valueEnum</span>: &#123;<br>    <span class="hljs-number">0</span>: &#123;<br>      <span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;普通用户&#x27;</span>,<br>      <span class="hljs-attr">status</span>: <span class="hljs-string">&#x27;Default&#x27;</span>,<br>    &#125;,<br>    <span class="hljs-number">1</span>: &#123;<br>      <span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;管理员&#x27;</span>,<br>      <span class="hljs-attr">status</span>: <span class="hljs-string">&#x27;Success&#x27;</span>,<br>    &#125;,<br>  &#125;,<br>&#125;,<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123;<br>  <span class="hljs-attr">title</span>: <span class="hljs-string">&#x27;状态&#x27;</span>,<br>  <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&#x27;userStatus&#x27;</span>,<br>  <span class="hljs-attr">valueType</span>: <span class="hljs-string">&#x27;select&#x27;</span>,<br>  <span class="hljs-attr">valueEnum</span>: &#123;<br>    <span class="hljs-number">0</span>: &#123;<br>      <span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;正常&#x27;</span>,<br>      <span class="hljs-attr">status</span>: <span class="hljs-string">&#x27;Success&#x27;</span>,<br>    &#125;,<br>    <span class="hljs-number">1</span>: &#123;<br>      <span class="hljs-attr">text</span>: <span class="hljs-string">&#x27;异常&#x27;</span>,<br>      <span class="hljs-attr">status</span>: <span class="hljs-string">&#x27;Error&#x27;</span>,<br>    &#125;,<br>  &#125;,<br>&#125;,<br></code></pre></td></tr></table></figure>

<h1 id="代码优化"><a href="#代码优化" class="headerlink" title="代码优化"></a>代码优化</h1><h2 id="新增注销功能"><a href="#新增注销功能" class="headerlink" title="新增注销功能"></a>新增注销功能</h2><ul>
<li>service 层新增 userLogout</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-type">int</span> <span class="hljs-title function_">userLogout</span><span class="hljs-params">(HttpServletRequest request)</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 用户注销</span><br><span class="hljs-comment">    *</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> request</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-meta">@Override</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">userLogout</span><span class="hljs-params">(HttpServletRequest request)</span> &#123;<br>   <span class="hljs-comment">// 移除session</span><br>       request.getSession().removeAttribute(USER_LOGIN_STATE);<br>       <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;<br>   &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>controller 层新增 userLogout</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 用户登录</span><br><span class="hljs-comment">   *</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> request request</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@return</span> int</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-meta">@PostMapping(&quot;/logout&quot;)</span><br>  <span class="hljs-keyword">public</span> Integer <span class="hljs-title function_">userLogout</span><span class="hljs-params">(HttpServletRequest request)</span> &#123;<br>      <span class="hljs-comment">//controller对参数的校验</span><br>      <span class="hljs-keyword">if</span> (request == <span class="hljs-literal">null</span>)<br>          <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br><br>      <span class="hljs-keyword">return</span> userService.userLogout(request);<br>  &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>前端 src/RightContent/AvatarDropdown.tsx 下有注销功能</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 退出登录，并且将当前的 url 保存</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">const</span> <span class="hljs-title function_">loginOut</span> = <span class="hljs-keyword">async</span> (<span class="hljs-params"></span>) =&gt; &#123;<br>  <span class="hljs-keyword">await</span> <span class="hljs-title function_">outLogin</span>();<br>  <span class="hljs-keyword">const</span> &#123; query = &#123;&#125;, search, pathname &#125; = history.<span class="hljs-property">location</span>;<br>  <span class="hljs-keyword">const</span> &#123; redirect &#125; = query;<br>  <span class="hljs-comment">// Note: There may be security issues, please note</span><br>  <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">window</span>.<span class="hljs-property">location</span>.<span class="hljs-property">pathname</span> !== <span class="hljs-string">&quot;/user/login&quot;</span> &amp;&amp; !redirect) &#123;<br>    history.<span class="hljs-title function_">replace</span>(&#123;<br>      <span class="hljs-attr">pathname</span>: <span class="hljs-string">&quot;/user/login&quot;</span>,<br>      <span class="hljs-attr">search</span>: <span class="hljs-title function_">stringify</span>(&#123;<br>        <span class="hljs-attr">redirect</span>: pathname + search,<br>      &#125;),<br>    &#125;);<br>  &#125;<br>&#125;;<br></code></pre></td></tr></table></figure>

<ul>
<li>修改注销接口 请求路径</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/** 退出登录接口 POST /api/user/logout */</span><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">outLogin</span>(<span class="hljs-params">options?: &#123; [key: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span> &#125;</span>) &#123;<br>  <span class="hljs-keyword">return</span> request&lt;<span class="hljs-title class_">Record</span>&lt;<span class="hljs-built_in">string</span>, <span class="hljs-built_in">any</span>&gt;&gt;(<span class="hljs-string">&quot;/api/user/logout&quot;</span>, &#123;<br>    <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>    ...(options || &#123;&#125;),<br>  &#125;);<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="注销功能优化完毕"><a href="#注销功能优化完毕" class="headerlink" title="注销功能优化完毕"></a>注销功能优化完毕</h4><h2 id="用户必填信息新增星球编号"><a href="#用户必填信息新增星球编号" class="headerlink" title="用户必填信息新增星球编号"></a>用户必填信息新增星球编号</h2><ul>
<li>user 表新增字段 planet_code</li>
<li>重新生成对应实体类 domain Mapper.xml</li>
<li>注册接收类新增 planetCode</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Data</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserRegisterRequest</span> &#123;<br>    <span class="hljs-keyword">private</span> String userAccount;<br>    <span class="hljs-keyword">private</span> String userPassword;<br>    <span class="hljs-keyword">private</span> String checkPassword;<br>    <span class="hljs-keyword">private</span> String planetCode;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>service 层</p>
<ul>
<li>注册校验新增</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-type">long</span> <span class="hljs-title function_">userRegister</span><span class="hljs-params">(String userAccount, String userPassword, String checkPassword, String planetCode)</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.6.星球编号不能超过5位</span><br>       <span class="hljs-keyword">if</span> (planetCode.length() &gt; <span class="hljs-number">5</span>)<br>           <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.8.星球编号不能重复</span><br>       QueryWrapper&lt;User&gt; pc_lqw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;();<br>       pc_lqw.eq(<span class="hljs-string">&quot;planet_code&quot;</span>, planetCode);<br>       <span class="hljs-type">Long</span> <span class="hljs-variable">pc_count</span> <span class="hljs-operator">=</span> userMapper.selectCount(pc_lqw);<br>       <span class="hljs-keyword">if</span> (pc_count &gt; <span class="hljs-number">0</span>)<br>           <span class="hljs-keyword">return</span> -<span class="hljs-number">1</span>;<br></code></pre></td></tr></table></figure>

<ul>
<li>用户信息脱敏新增</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs java">safetyUser.setPlanetCode(originUser.getPlanetCode());<br></code></pre></td></tr></table></figure>

<p>controller 层</p>
<ul>
<li>controller 参数校验</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">//controller对参数的校验</span><br><span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword, planetCode))<br>    <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;<br></code></pre></td></tr></table></figure>

<ul>
<li>注册页面新增星球编号填写和校验</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;ProFormText name=&quot;planetCode&quot; fieldProps=&#123;&#123; size: &#x27;large&#x27;, prefix:<br>&lt;LockOutlined className=&quot;&#123;styles.prefixIcon&#125;&quot; /&gt;<br>, &#125;&#125; placeholder=&#123;&#x27;请输入星球编号&#x27;&#125; rules=&#123;[ &#123; required: true, message:<br>&#x27;星球编号是必填项！&#x27;, &#125;, &#123; max: 5, type: &#x27;string&#x27;, message: &#x27;长度不能大于5位&#x27;,<br>&#125;, ]&#125; /&gt;<br></code></pre></td></tr></table></figure>

<ul>
<li>测试类新增 planetCode</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Test</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">userRegister</span><span class="hljs-params">()</span> &#123;<br>    <span class="hljs-type">String</span> <span class="hljs-variable">userAccount</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;memory&quot;</span>;<br>    <span class="hljs-type">String</span> <span class="hljs-variable">userPassword</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>;<br>    <span class="hljs-type">String</span> <span class="hljs-variable">checkPassword</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;123456&quot;</span>;<br>    <span class="hljs-type">String</span> <span class="hljs-variable">planetCode</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;17265&quot;</span>;<br><br>    <span class="hljs-type">long</span> <span class="hljs-variable">result</span> <span class="hljs-operator">=</span> userService.userRegister(userAccount, userPassword, checkPassword, planetCode);<br>    Assertions.assertEquals(-<span class="hljs-number">1</span>, result);<br>    userAccount = <span class="hljs-string">&quot;mem&quot;</span>;<br>    result = userService.userRegister(userAccount, userPassword, checkPassword, planetCode);<br>    Assertions.assertEquals(-<span class="hljs-number">1</span>, result);<br>    userPassword = <span class="hljs-string">&quot;123456&quot;</span>;<br>    result = userService.userRegister(userAccount, userPassword, checkPassword, planetCode);<br>    Assertions.assertEquals(-<span class="hljs-number">1</span>, result);<br>    userAccount = <span class="hljs-string">&quot;me mory&quot;</span>;<br>    userPassword = <span class="hljs-string">&quot;12345678&quot;</span>;<br>    result = userService.userRegister(userAccount, userPassword, checkPassword, planetCode);<br>    Assertions.assertEquals(-<span class="hljs-number">1</span>, result);<br>    userAccount = <span class="hljs-string">&quot;me mory&quot;</span>;<br>    checkPassword = <span class="hljs-string">&quot;12345678&quot;</span>;<br>    result = userService.userRegister(userAccount, userPassword, checkPassword, planetCode);<br>    Assertions.assertEquals(-<span class="hljs-number">1</span>, result);<br>    userAccount = <span class="hljs-string">&quot;memory4&quot;</span>;<br>    result = userService.userRegister(userAccount, userPassword, checkPassword, planetCode);<br>    Assertions.assertTrue(result &gt; <span class="hljs-number">0</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li>currentUser 新增 planetCode</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">type</span> <span class="hljs-title class_">CurrentUser</span> = &#123;<br>  id?: <span class="hljs-built_in">number</span>;<br>  userAccount?: <span class="hljs-built_in">string</span>;<br>  username?: <span class="hljs-built_in">string</span>;<br>  avatarUrl?: <span class="hljs-built_in">string</span>;<br>  gender?: <span class="hljs-built_in">string</span>;<br>  phone?: <span class="hljs-built_in">string</span>;<br>  email?: <span class="hljs-built_in">string</span>;<br>  createTime?: <span class="hljs-title class_">Date</span>;<br>  userStatus?: <span class="hljs-built_in">string</span>;<br>  userRole?: <span class="hljs-built_in">number</span>;<br>  planetCode?: <span class="hljs-built_in">string</span>;<br>&#125;;<br></code></pre></td></tr></table></figure>

<ul>
<li>管理页用户信息新增 planetCode</li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&#123;<br>  <span class="hljs-attr">title</span>: <span class="hljs-string">&#x27;星球编号&#x27;</span>,<br>  <span class="hljs-attr">dataIndex</span>: <span class="hljs-string">&#x27;planetCode&#x27;</span>,<br>  <span class="hljs-attr">copyable</span>: <span class="hljs-literal">true</span>,<br>&#125;,<br></code></pre></td></tr></table></figure>

<h4 id="新增星球编号注册必填项完成-管理页用户信息正常显示"><a href="#新增星球编号注册必填项完成-管理页用户信息正常显示" class="headerlink" title="新增星球编号注册必填项完成, 管理页用户信息正常显示"></a>新增星球编号注册必填项完成, 管理页用户信息正常显示</h4><h2 id="返回通用对象"><a href="#返回通用对象" class="headerlink" title="返回通用对象"></a>返回通用对象</h2><ul>
<li><h5 id="自定义通用返回对象-BaseResponse"><a href="#自定义通用返回对象-BaseResponse" class="headerlink" title="自定义通用返回对象 - BaseResponse"></a>自定义通用返回对象 - BaseResponse</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 状态码</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">private</span> <span class="hljs-type">int</span> code;<br><br>  <span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 数据</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">private</span> T data;<br><br>  <span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 信息</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">private</span> String message;<br><br>  <span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 描述</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">private</span> String description;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="通用返回对象多种构造器"><a href="#通用返回对象多种构造器" class="headerlink" title="通用返回对象多种构造器"></a>通用返回对象多种构造器</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 封装执行成功的结果</span><br><span class="hljs-comment">    *</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> code        状态码</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> data        数据</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> message     信息</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> description 描述</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-title function_">BaseResponse</span><span class="hljs-params">(<span class="hljs-type">int</span> code, T data, String message, String description)</span> &#123;<br>       <span class="hljs-built_in">this</span>.code = code;<br>       <span class="hljs-built_in">this</span>.data = data;<br>       <span class="hljs-built_in">this</span>.message = message;<br>       <span class="hljs-built_in">this</span>.description = description;<br>   &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 封装全局自定义异常</span><br><span class="hljs-comment">    *</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> code        状态码</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> message     信息</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> description 描述</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-title function_">BaseResponse</span><span class="hljs-params">(<span class="hljs-type">int</span> code, String message, String description)</span> &#123;<br>       <span class="hljs-built_in">this</span>.code = code;<br>       <span class="hljs-built_in">this</span>.data = <span class="hljs-literal">null</span>;<br>       <span class="hljs-built_in">this</span>.message = message;<br>       <span class="hljs-built_in">this</span>.description = description;<br>   &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 封装局部自定义异常</span><br><span class="hljs-comment">   *</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> errorCode 自定义异常态</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">public</span> <span class="hljs-title function_">BaseResponse</span><span class="hljs-params">(ErrorCode errorCode)</span> &#123;<br>      <span class="hljs-built_in">this</span>.code = errorCode.getCode();<br>      <span class="hljs-built_in">this</span>.data = <span class="hljs-literal">null</span>;<br>      <span class="hljs-built_in">this</span>.message = errorCode.getMessage();<br>      <span class="hljs-built_in">this</span>.description = errorCode.getDescription();<br>  &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="通用返回对象添加-getter-setter-方法"><a href="#通用返回对象添加-getter-setter-方法" class="headerlink" title="通用返回对象添加 getter, setter 方法"></a>通用返回对象添加 getter, setter 方法</h5></li>
<li><h5 id="这一步一定不要忘记啊-我就因为没加这俩方法-测试登录注册就报-406-错误"><a href="#这一步一定不要忘记啊-我就因为没加这俩方法-测试登录注册就报-406-错误" class="headerlink" title="这一步一定不要忘记啊, 我就因为没加这俩方法, 测试登录注册就报 406 错误"></a>这一步一定不要忘记啊, 我就因为没加这俩方法, 测试登录注册就报 406 错误</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">getCode</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> code;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> T <span class="hljs-title function_">getData</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> data;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getMessage</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> message;<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getDescription</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> description;<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setCode</span><span class="hljs-params">(<span class="hljs-type">int</span> code)</span> &#123;<br>    <span class="hljs-built_in">this</span>.code = code;<br>&#125;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setData</span><span class="hljs-params">(T data)</span> &#123;<br>    <span class="hljs-built_in">this</span>.data = data;<br>&#125;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setMessage</span><span class="hljs-params">(String message)</span> &#123;<br>    <span class="hljs-built_in">this</span>.message = message;<br>&#125;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setDescription</span><span class="hljs-params">(String description)</span> &#123;<br>    <span class="hljs-built_in">this</span>.description = description;<br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="返回成功的话-就是返回成功状态-即返回状态码-数据-“ok”-message-“”-description"><a href="#返回成功的话-就是返回成功状态-即返回状态码-数据-“ok”-message-“”-description" class="headerlink" title="返回成功的话, 就是返回成功状态, 即返回状态码 + 数据 + “ok”(message) + “”(description)"></a>返回成功的话, 就是返回成功状态, 即返回状态码 + 数据 + “ok”(message) + “”(description)</h4><ul>
<li><h5 id="封装返回成功状态下通用对象的方法"><a href="#封装返回成功状态下通用对象的方法" class="headerlink" title="封装返回成功状态下通用对象的方法"></a>封装返回成功状态下通用对象的方法</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 封装调用执行成功</span><br><span class="hljs-comment">    *</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> data 返回数据</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> &lt;T&gt;  数据类型</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@return</span> 执行成功信息</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> &lt;T&gt; BaseResponse&lt;T&gt; <span class="hljs-title function_">success</span><span class="hljs-params">(T data)</span> &#123;<br>       <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BaseResponse</span>&lt;&gt;(<span class="hljs-number">0</span>, data, <span class="hljs-string">&quot;ok&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);<br>   &#125;<br></code></pre></td></tr></table></figure>

<h4 id="返回失败的话-就是返回失败状态-即返回状态码-null-data-message-description"><a href="#返回失败的话-就是返回失败状态-即返回状态码-null-data-message-description" class="headerlink" title="返回失败的话, 就是返回失败状态, 即返回状态码 + null(data) + message + description"></a>返回失败的话, 就是返回失败状态, 即返回状态码 + null(data) + message + description</h4><h4 id="实现思路-这里我们打算封装自定义异常类和全局异常处理器-当业务中出现错误-不会返回失败结果-而是抛出相应的异常-并由全局异常处理器捕获-再由全局异常处理器来返回对应失败状态"><a href="#实现思路-这里我们打算封装自定义异常类和全局异常处理器-当业务中出现错误-不会返回失败结果-而是抛出相应的异常-并由全局异常处理器捕获-再由全局异常处理器来返回对应失败状态" class="headerlink" title="实现思路: 这里我们打算封装自定义异常类和全局异常处理器, 当业务中出现错误, 不会返回失败结果, 而是抛出相应的异常, 并由全局异常处理器捕获, 再由全局异常处理器来返回对应失败状态"></a>实现思路: 这里我们打算封装自定义异常类和全局异常处理器, 当业务中出现错误, 不会返回失败结果, 而是抛出相应的异常, 并由全局异常处理器捕获, 再由全局异常处理器来返回对应失败状态</h4><h2 id="封装自定义异常-BusinessException"><a href="#封装自定义异常-BusinessException" class="headerlink" title="封装自定义异常 BusinessException"></a>封装自定义异常 BusinessException</h2><h5 id="自定义异常成员属性"><a href="#自定义异常成员属性" class="headerlink" title="自定义异常成员属性"></a>自定义异常成员属性</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">BusinessException</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">RuntimeException</span> &#123;<br> <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 状态码</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> code;<br><br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 异常描述</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String description;<br>................<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="这里我们会发现-自定义异常里没有定义-message-属性-这是因为自定义异常继承了-RuntimeException-在执行构造方法时-执行-super-message-即可设置自定义的异常信息-再通过-e-getMessage-方法来获取异常信息"><a href="#这里我们会发现-自定义异常里没有定义-message-属性-这是因为自定义异常继承了-RuntimeException-在执行构造方法时-执行-super-message-即可设置自定义的异常信息-再通过-e-getMessage-方法来获取异常信息" class="headerlink" title="这里我们会发现, 自定义异常里没有定义 message 属性. 这是因为自定义异常继承了 RuntimeException, 在执行构造方法时, 执行 super(message)即可设置自定义的异常信息, 再通过 e.getMessage()方法来获取异常信息"></a>这里我们会发现, 自定义异常里没有定义 message 属性. 这是因为自定义异常继承了 RuntimeException, 在执行构造方法时, 执行 super(message)即可设置自定义的异常信息, 再通过 e.getMessage()方法来获取异常信息</h5></li>
<li><h5 id="自定义异常多种构造器"><a href="#自定义异常多种构造器" class="headerlink" title="自定义异常多种构造器"></a>自定义异常多种构造器</h5></li>
<li><h5 id="局部业务代码下自定义的异常信息"><a href="#局部业务代码下自定义的异常信息" class="headerlink" title="局部业务代码下自定义的异常信息"></a>局部业务代码下自定义的异常信息</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 封装局部自定义异常</span><br><span class="hljs-comment">   *</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> message     异常信息</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> code        异常状态码</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> description 异常描述</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">public</span> <span class="hljs-title function_">BusinessException</span><span class="hljs-params">(String message, <span class="hljs-type">int</span> code, String description)</span> &#123;<br>      <span class="hljs-built_in">super</span>(message);<br>      <span class="hljs-built_in">this</span>.code = code;<br>      <span class="hljs-built_in">this</span>.description = description;<br>  &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="封装全局自定义异常-无描述"><a href="#封装全局自定义异常-无描述" class="headerlink" title="封装全局自定义异常(无描述)"></a>封装全局自定义异常(无描述)</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * 封装全局自定义异常(无描述)</span><br><span class="hljs-comment">   *</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> errorCode 自定义异常态</span><br><span class="hljs-comment">   */</span><br>  <span class="hljs-keyword">public</span> <span class="hljs-title function_">BusinessException</span><span class="hljs-params">(ErrorCode errorCode)</span> &#123;<br>      <span class="hljs-built_in">super</span>(errorCode.getMessage());<br>      <span class="hljs-built_in">this</span>.code = errorCode.getCode();<br>      <span class="hljs-built_in">this</span>.description = errorCode.getDescription();<br>  &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="封装全局自定义异常-有描述"><a href="#封装全局自定义异常-有描述" class="headerlink" title="封装全局自定义异常(有描述)"></a>封装全局自定义异常(有描述)</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">  * 封装全局自定义异常(有描述)</span><br><span class="hljs-comment">  *</span><br><span class="hljs-comment">  * <span class="hljs-doctag">@param</span> errorCode   自定义异常态</span><br><span class="hljs-comment">  * <span class="hljs-doctag">@param</span> description 异常描述</span><br><span class="hljs-comment">  */</span><br> <span class="hljs-keyword">public</span> <span class="hljs-title function_">BusinessException</span><span class="hljs-params">(ErrorCode errorCode, String description)</span> &#123;<br>     <span class="hljs-built_in">super</span>(errorCode.getMessage());<br>     <span class="hljs-built_in">this</span>.code = errorCode.getCode();<br>     <span class="hljs-built_in">this</span>.description = description;<br> &#125;<br></code></pre></td></tr></table></figure>

<h3 id="补充-封装全局自定义异常信息-ErrorCode-枚举类"><a href="#补充-封装全局自定义异常信息-ErrorCode-枚举类" class="headerlink" title="补充: 封装全局自定义异常信息 ErrorCode (枚举类)"></a>补充: 封装全局自定义异常信息 ErrorCode (枚举类)</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> <span class="hljs-title class_">ErrorCode</span> &#123;<br>	..............<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="枚举值-需持续完善更新"><a href="#枚举值-需持续完善更新" class="headerlink" title="枚举值 (需持续完善更新)"></a>枚举值 (需持续完善更新)</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java">PARMS_ERROR(<span class="hljs-number">40000</span>, <span class="hljs-string">&quot;请求参数错误&quot;</span>, <span class="hljs-string">&quot;&quot;</span>),<br>NULL_ERROR(<span class="hljs-number">40001</span>, <span class="hljs-string">&quot;请求数据为空&quot;</span>, <span class="hljs-string">&quot;&quot;</span>),<br>UPDATE_ERROR(<span class="hljs-number">40002</span>, <span class="hljs-string">&quot;操作数据库失败&quot;</span>, <span class="hljs-string">&quot;&quot;</span>),<br>NOT_LOGIN(<span class="hljs-number">40003</span>, <span class="hljs-string">&quot;未登录&quot;</span>, <span class="hljs-string">&quot;&quot;</span>),<br>NOT_REGISTER(<span class="hljs-number">40004</span>, <span class="hljs-string">&quot;未注册&quot;</span>, <span class="hljs-string">&quot;&quot;</span>),<br>NO_AUTH(<span class="hljs-number">40005</span>, <span class="hljs-string">&quot;无权限&quot;</span>, <span class="hljs-string">&quot;&quot;</span>),<br>SYSTEM_ERROR(<span class="hljs-number">10000</span>, <span class="hljs-string">&quot;系统内部异常&quot;</span>, <span class="hljs-string">&quot;&quot;</span>);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="成员属性"><a href="#成员属性" class="headerlink" title="成员属性"></a>成员属性</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 状态码</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-type">int</span> code;<br><br>   <span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 状态码信息</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String message;<br><br>   <span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 状态码描述</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String description;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="构造器和-getter-方法"><a href="#构造器和-getter-方法" class="headerlink" title="构造器和 getter 方法"></a>构造器和 getter 方法</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> code        状态码</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> message     信息</span><br><span class="hljs-comment">   * <span class="hljs-doctag">@param</span> description 描述</span><br><span class="hljs-comment">   */</span><br>  ErrorCode(<span class="hljs-type">int</span> code, String message, String description) &#123;<br>      <span class="hljs-built_in">this</span>.code = code;<br>      <span class="hljs-built_in">this</span>.message = message;<br>      <span class="hljs-built_in">this</span>.description = description;<br>  &#125;<br><br>  <span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">getCode</span><span class="hljs-params">()</span> &#123;<br>      <span class="hljs-keyword">return</span> code;<br>  &#125;<br><br>  <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getMessage</span><span class="hljs-params">()</span> &#123;<br>      <span class="hljs-keyword">return</span> message;<br>  &#125;<br><br>  <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getDescription</span><span class="hljs-params">()</span> &#123;<br>      <span class="hljs-keyword">return</span> description;<br>  &#125;<br></code></pre></td></tr></table></figure>

<h5 id="自定义异常-getter-方法"><a href="#自定义异常-getter-方法" class="headerlink" title="自定义异常 getter 方法"></a>自定义异常 getter 方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">public</span> <span class="hljs-type">int</span> <span class="hljs-title function_">getCode</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> code;<br>    &#125;<br><br><span class="hljs-keyword">public</span> String <span class="hljs-title function_">getDescription</span><span class="hljs-params">()</span> &#123;<br>        <span class="hljs-keyword">return</span> description;<br>    &#125;<br></code></pre></td></tr></table></figure>

<h2 id="封装全局异常处理器"><a href="#封装全局异常处理器" class="headerlink" title="封装全局异常处理器"></a>封装全局异常处理器</h2><h5 id=""><a href="#" class="headerlink" title=""></a><!--熟悉全局异常处理器的写法和实现过程, 了解其实现原理--></h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@RestControllerAdvice</span><br><span class="hljs-meta">@Slf4j</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">GlobalExceptionHandler</span> &#123;<br>	....................<br>&#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="捕获自定义异常对象"><a href="#捕获自定义异常对象" class="headerlink" title="捕获自定义异常对象"></a>捕获自定义异常对象</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 捕获自定义异常对象</span><br><span class="hljs-comment">    *</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> e 自定义异常</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@return</span> 封装返回执行失败异常信息</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-meta">@ExceptionHandler(BusinessException.class)</span><br>   <span class="hljs-keyword">public</span> BaseResponse <span class="hljs-title function_">locallyCustomException</span><span class="hljs-params">(BusinessException e)</span> &#123;<br>       log.error(<span class="hljs-string">&quot;businessException: &quot;</span> + e.getMessage(), e);<br>       log.info(<span class="hljs-string">&quot;&quot;</span> + e.getCode());<br>       log.info(e.getMessage());<br>       log.info(e.getDescription());<br>       <span class="hljs-keyword">return</span> ResultUtils.error(e.getCode(), e.getMessage(), e.getDescription());<br>   &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="捕获其他异常"><a href="#捕获其他异常" class="headerlink" title="捕获其他异常"></a>捕获其他异常</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">    * 捕获其他异常</span><br><span class="hljs-comment">    *</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@param</span> e 其他异常</span><br><span class="hljs-comment">    * <span class="hljs-doctag">@return</span> 封装返回请求失败异常信息</span><br><span class="hljs-comment">    */</span><br>   <span class="hljs-meta">@ExceptionHandler(RuntimeException.class)</span><br>   <span class="hljs-keyword">public</span> BaseResponse <span class="hljs-title function_">globalCustomException</span><span class="hljs-params">(Exception e)</span> &#123;<br>       log.error(<span class="hljs-string">&quot;runtimeException&quot;</span>, e);<br>       <span class="hljs-keyword">return</span> ResultUtils.error(ErrorCode.SYSTEM_ERROR);<br>   &#125;<br></code></pre></td></tr></table></figure>

<h2 id="修改后端返回给前端的数据-全部更新为直接返回通用对象-成功状态-或抛出业务异常再由全局异常处理器返回通用对象-失败状态"><a href="#修改后端返回给前端的数据-全部更新为直接返回通用对象-成功状态-或抛出业务异常再由全局异常处理器返回通用对象-失败状态" class="headerlink" title="修改后端返回给前端的数据, 全部更新为直接返回通用对象(成功状态)或抛出业务异常再由全局异常处理器返回通用对象(失败状态)"></a>修改后端返回给前端的数据, 全部更新为直接返回通用对象(成功状态)或抛出业务异常再由全局异常处理器返回通用对象(失败状态)</h2><ul>
<li><h5 id="成功状态-controller-层"><a href="#成功状态-controller-层" class="headerlink" title="成功状态 (controller 层)"></a>成功状态 (controller 层)</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 用户注册</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> userRegisterRequest 注册信息封装类</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> id</span><br><span class="hljs-comment">     */</span><br><span class="hljs-keyword">public</span> BaseResponse&lt;Long&gt; <span class="hljs-title function_">userRegister</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> UserRegisterRequest userRegisterRequest)</span> &#123;<br>    ......................<br>    <span class="hljs-keyword">return</span> ResultUtils.success(userRegister);<br>&#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 用户登录</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> userLoginRequest 登录信息封装</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> request          request</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> User</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@PostMapping(&quot;/login&quot;)</span><br>    <span class="hljs-keyword">public</span> BaseResponse&lt;User&gt; <span class="hljs-title function_">userLogin</span><span class="hljs-params">(<span class="hljs-meta">@RequestBody</span> UserLoginRequest userLoginRequest, HttpServletRequest request)</span> &#123;<br>        .........................<br>        <span class="hljs-keyword">return</span> ResultUtils.success(userLogin);<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 用户登录</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> request request</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> int</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@PostMapping(&quot;/logout&quot;)</span><br>    <span class="hljs-keyword">public</span> BaseResponse&lt;String&gt; <span class="hljs-title function_">userLogout</span><span class="hljs-params">(HttpServletRequest request)</span> &#123;<br>        ..........................<br>        <span class="hljs-keyword">return</span> ResultUtils.success(userLogout);<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 获取当前用户登录态</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> request request</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> 当前用户信息</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/currentUser&quot;)</span><br>    <span class="hljs-keyword">public</span> BaseResponse&lt;User&gt; <span class="hljs-title function_">getCurrentUser</span><span class="hljs-params">(HttpServletRequest request)</span> &#123;<br>        ............................<br>        <span class="hljs-keyword">return</span> ResultUtils.success(user);<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 查询用户</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> username 用户名</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> 查到的用户</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@GetMapping(&quot;/search&quot;)</span><br>    <span class="hljs-keyword">public</span> BaseResponse&lt;List&lt;User&gt;&gt; <span class="hljs-title function_">userSearch</span><span class="hljs-params">(String username, HttpServletRequest request)</span> &#123;<br>        .............................<br>        <span class="hljs-keyword">return</span> ResultUtils.success(users);<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 删除用户</span><br><span class="hljs-comment">     *</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> id 用户id</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> true/false</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@DeleteMapping(&quot;/delete&quot;)</span><br>    <span class="hljs-keyword">public</span> BaseResponse&lt;Boolean&gt; <span class="hljs-title function_">userDelete</span><span class="hljs-params">(Long id, HttpServletRequest request)</span> &#123;<br>        ..............................<br>        <span class="hljs-keyword">return</span> ResultUtils.success(removeById);<br>    &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword, planetCode))<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<h5 id="失败状态"><a href="#失败状态" class="headerlink" title="失败状态"></a>失败状态</h5><ul>
<li><h5 id="controller-层-register-login-logout-currentUser-search-delete-下的-controller-参数校验"><a href="#controller-层-register-login-logout-currentUser-search-delete-下的-controller-参数校验" class="headerlink" title="controller 层 register login logout currentUser search delete 下的 controller 参数校验"></a>controller 层 register login logout currentUser search delete 下的 controller 参数校验</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword, planetCode))<br>       <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword))<br>        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (request == <span class="hljs-literal">null</span>)<br>        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (currentUser == <span class="hljs-literal">null</span>)<br>        <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (!isAdmin(request))<br>         <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(NO_AUTH);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">if</span> (!isAdmin(request))<br>          <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(NO_AUTH);<br><span class="hljs-keyword">if</span> (id &lt;= <span class="hljs-number">0</span>)<br>          <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="service-层-register-下的参数校验"><a href="#service-层-register-下的参数校验" class="headerlink" title="service 层 register 下的参数校验"></a>service 层 register 下的参数校验</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.1.账户, 密码, 二次密码不能为空</span><br>        <span class="hljs-keyword">if</span> (StringUtils.isAnyBlank(userAccount, userPassword, checkPassword))<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(PARMS_ERROR);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.2.账户不小于4位</span><br>        <span class="hljs-keyword">if</span> (userAccount.length() &lt; <span class="hljs-number">4</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;账户不符合要求&quot;</span>, <span class="hljs-number">50000</span>, <span class="hljs-string">&quot;账户小于4位&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.3.账户不包含特殊字符</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">pattern</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;.*[\\s`~!@#$%^&amp;*()+=|&#123;&#125;&#x27;:;&#x27;,\\[\\].&lt;&gt;/?~！@#￥%……&amp;*（）——+|&#123;&#125;【】‘；：”“’。，、？\\\\]+.*&quot;</span>;<br>        <span class="hljs-keyword">if</span> (Pattern.matches(pattern, userAccount))<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;账户不符合要求&quot;</span>, <span class="hljs-number">50001</span>, <span class="hljs-string">&quot;账户包含特殊字符&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.4.用户密码不小于8位</span><br>        <span class="hljs-keyword">if</span> (userPassword.length() &lt; <span class="hljs-number">8</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;密码不符合要求&quot;</span>, <span class="hljs-number">60000</span>, <span class="hljs-string">&quot;用户密码小于8位&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.5.二次密码与密码相同</span><br>        <span class="hljs-keyword">if</span> (!userPassword.equals(checkPassword))<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;二次密码不符合要求&quot;</span>, <span class="hljs-number">60001</span>, <span class="hljs-string">&quot;二次密码与密码不相同&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.6.星球编号不能超过5位</span><br>        <span class="hljs-keyword">if</span> (planetCode.length() &gt; <span class="hljs-number">5</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;星球编号不符合要求&quot;</span>, <span class="hljs-number">60002</span>, <span class="hljs-string">&quot;星球编号超过5位&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.7.账户不能重复</span><br>        QueryWrapper&lt;User&gt; ua_lqw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;(); <span class="hljs-comment">// LambdaQueryWrapper&lt;User&gt; userLambdaQueryWrapper = new LambdaQueryWrapper&lt;&gt;();</span><br>        ua_lqw.eq(<span class="hljs-string">&quot;user_account&quot;</span>, userAccount); <span class="hljs-comment">// userLambdaQueryWrapper.eq(User::getUserAccount, userAccount);</span><br>        <span class="hljs-type">Long</span> <span class="hljs-variable">ua_count</span> <span class="hljs-operator">=</span> userMapper.selectCount(ua_lqw);   <span class="hljs-comment">// long count = this.count(lqw);</span><br>        <span class="hljs-keyword">if</span> (ua_count &gt; <span class="hljs-number">0</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;账户不符合要求&quot;</span>, <span class="hljs-number">50002</span>, <span class="hljs-string">&quot;账户重复&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.8.星球编号不能重复</span><br>        QueryWrapper&lt;User&gt; pc_lqw = <span class="hljs-keyword">new</span> <span class="hljs-title class_">QueryWrapper</span>&lt;&gt;();<br>        pc_lqw.eq(<span class="hljs-string">&quot;planet_code&quot;</span>, planetCode);<br>        <span class="hljs-type">Long</span> <span class="hljs-variable">pc_count</span> <span class="hljs-operator">=</span> userMapper.selectCount(pc_lqw);<br>        <span class="hljs-keyword">if</span> (pc_count &gt; <span class="hljs-number">0</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;星球编号不符合要求&quot;</span>, <span class="hljs-number">60003</span>, <span class="hljs-string">&quot;星球编号重复&quot;</span>);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="service-层-login-下的参数校验"><a href="#service-层-login-下的参数校验" class="headerlink" title="service 层 login 下的参数校验"></a>service 层 login 下的参数校验</h5></li>
</ul>
<figure class="highlight reasonml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs reasonml"><span class="hljs-comment">// 1.1.账户, 密码不能为空</span><br>        <span class="hljs-keyword">if</span> (<span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">StringUtils</span>.</span></span>is<span class="hljs-constructor">AnyBlank(<span class="hljs-params">userAccount</span>, <span class="hljs-params">userPassword</span>)</span>)<br>            throw <span class="hljs-keyword">new</span> <span class="hljs-constructor">BusinessException(PARMS_ERROR)</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.2.账户不小于4位</span><br>        <span class="hljs-keyword">if</span> (userAccount.length() &lt; <span class="hljs-number">4</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;账户不符合要求&quot;</span>, <span class="hljs-number">50000</span>, <span class="hljs-string">&quot;账户小于4位&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.3.用户密码不小于8位</span><br>        <span class="hljs-keyword">if</span> (userPassword.length() &lt; <span class="hljs-number">8</span>)<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;密码不符合要求&quot;</span>, <span class="hljs-number">60000</span>, <span class="hljs-string">&quot;用户密码小于8位&quot;</span>);<br></code></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-comment">// 1.4.账户不包含特殊字符</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">pattern</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;.*[\\s`~!@#$%^&amp;*()+=|&#123;&#125;&#x27;:;&#x27;,\\[\\].&lt;&gt;/?~！@#￥%……&amp;*（）——+|&#123;&#125;【】‘；：”“’。，、？\\\\]+.*&quot;</span>;<br>        <span class="hljs-keyword">if</span> (Pattern.matches(pattern, userAccount))<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">BusinessException</span>(<span class="hljs-string">&quot;账户不符合要求&quot;</span>, <span class="hljs-number">50001</span>, <span class="hljs-string">&quot;账户包含特殊字符&quot;</span>);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="service-层-logout-下的返回信息"><a href="#service-层-logout-下的返回信息" class="headerlink" title="service 层 logout 下的返回信息"></a>service 层 logout 下的返回信息</h5></li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs java">request.getSession().removeAttribute(USER_LOGIN_STATE);<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;注销成功&quot;</span>;<br></code></pre></td></tr></table></figure>

<h5 id="自定义异常并由全局异常处理器成功处理-功能基本完成"><a href="#自定义异常并由全局异常处理器成功处理-功能基本完成" class="headerlink" title="自定义异常并由全局异常处理器成功处理, 功能基本完成"></a>自定义异常并由全局异常处理器成功处理, 功能基本完成</h5><h2 id="前端适配后端的通用返回对象"><a href="#前端适配后端的通用返回对象" class="headerlink" title="前端适配后端的通用返回对象"></a>前端适配后端的通用返回对象</h2><ul>
<li><h5 id="前端定义通用返回对象-services-ant-design-pro-typings-d-ts"><a href="#前端定义通用返回对象-services-ant-design-pro-typings-d-ts" class="headerlink" title="前端定义通用返回对象(services/ant-design-pro/typings.d.ts)"></a>前端定义通用返回对象(services/ant-design-pro/typings.d.ts)</h5></li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 通用返回类</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">type</span> <span class="hljs-title class_">BaseResponse</span>&lt;T&gt; = &#123;<br>  <span class="hljs-attr">code</span>: <span class="hljs-built_in">number</span>;<br>  <span class="hljs-attr">data</span>: T;<br>  <span class="hljs-attr">message</span>: <span class="hljs-built_in">string</span>;<br>  <span class="hljs-attr">description</span>: <span class="hljs-built_in">string</span>;<br>&#125;;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="封装各接口响应类型-services-ant-design-pro-api-ts"><a href="#封装各接口响应类型-services-ant-design-pro-api-ts" class="headerlink" title="封装各接口响应类型(services/ant-design-pro/api.ts)"></a>封装各接口响应类型(services/ant-design-pro/api.ts)</h5></li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;(<span class="hljs-string">&quot;/api/user/currentUser&quot;</span>, &#123;<br>  <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;GET&quot;</span>,<br>  ...(options || &#123;&#125;),<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;(<span class="hljs-string">&quot;/api/user/logout&quot;</span>, &#123;<br>  <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>  ...(options || &#123;&#125;),<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;(<span class="hljs-string">&quot;/api/user/login&quot;</span>, &#123;<br>  <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>  <span class="hljs-attr">headers</span>: &#123;<br>    <span class="hljs-string">&quot;Content-Type&quot;</span>: <span class="hljs-string">&quot;application/json&quot;</span>,<br>  &#125;,<br>  <span class="hljs-attr">data</span>: body,<br>  ...(options || &#123;&#125;),<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;(<span class="hljs-string">&quot;/api/user/register&quot;</span>, &#123;<br>  <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;POST&quot;</span>,<br>  <span class="hljs-attr">headers</span>: &#123;<br>    <span class="hljs-string">&quot;Content-Type&quot;</span>: <span class="hljs-string">&quot;application/json&quot;</span>,<br>  &#125;,<br>  <span class="hljs-attr">data</span>: body,<br>  ...(options || &#123;&#125;),<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">return</span> request&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;(<span class="hljs-string">&quot;/api/user/search&quot;</span>, &#123;<br>  <span class="hljs-attr">method</span>: <span class="hljs-string">&quot;GET&quot;</span>,<br>  ...(options || &#123;&#125;),<br>&#125;);<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="修改登录-注册成功的校验逻辑"><a href="#修改登录-注册成功的校验逻辑" class="headerlink" title="修改登录/注册成功的校验逻辑"></a>修改登录/注册成功的校验逻辑</h5></li>
</ul>
<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 登录</span><br><span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">login</span>(&#123;<br>  ...values,<br>  <span class="hljs-keyword">type</span>,<br>&#125;);<br><span class="hljs-comment">// 登录成功</span><br><span class="hljs-keyword">if</span> (data) &#123;<br>  <span class="hljs-keyword">const</span> defaultLoginSuccessMessage = <span class="hljs-string">&#x27;登录成功！&#x27;</span>;<br>  ................<br> &#125;<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">// 注册</span><br><span class="hljs-comment">// 返回id</span><br><span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">register</span>(&#123;<br>  ...values,<br>  <span class="hljs-keyword">type</span>,<br>&#125;);<br><span class="hljs-comment">// 注册成功</span><br><span class="hljs-keyword">if</span> (data) &#123;<br>  <span class="hljs-keyword">const</span> defaultLoginSuccessMessage = <span class="hljs-string">&#x27;注册成功！&#x27;</span>;<br>  ....................<br> &#125;<br></code></pre></td></tr></table></figure>

<ul>
<li><h5 id="这边还要记得修改两个地方"><a href="#这边还要记得修改两个地方" class="headerlink" title="这边还要记得修改两个地方:"></a>这边还要记得修改两个地方:</h5></li>
</ul>
<h6 id="修改管理员权限的校验-解决了无法正确访问到管理员页面的问题"><a href="#修改管理员权限的校验-解决了无法正确访问到管理员页面的问题" class="headerlink" title="修改管理员权限的校验 - 解决了无法正确访问到管理员页面的问题"></a>修改管理员权限的校验 - 解决了无法正确访问到管理员页面的问题</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">access</span>(<span class="hljs-params"></span><br><span class="hljs-params">  initialState: &#123; baseResponse?: API.BaseResponse&lt;API.CurrentUser&gt; &#125; | <span class="hljs-literal">undefined</span></span><br><span class="hljs-params"></span>) &#123;<br>  <span class="hljs-keyword">const</span> &#123; baseResponse &#125; = initialState ?? &#123;&#125;;<br>  <span class="hljs-comment">// 权限校验</span><br>  <span class="hljs-keyword">return</span> &#123;<br>    <span class="hljs-comment">// 校验管理员权限</span><br>    <span class="hljs-attr">canAdmin</span>: baseResponse &amp;&amp; baseResponse.<span class="hljs-property">data</span>.<span class="hljs-property">userRole</span> === <span class="hljs-number">1</span>,<br>  &#125;;<br>&#125;<br></code></pre></td></tr></table></figure>

<h6 id="修改查询在线用户信息-解决了在线用户信息页面无法正常显示的问题"><a href="#修改查询在线用户信息-解决了在线用户信息页面无法正常显示的问题" class="headerlink" title="修改查询在线用户信息 - 解决了在线用户信息页面无法正常显示的问题"></a>修改查询在线用户信息 - 解决了在线用户信息页面无法正常显示的问题</h6><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">const</span> <span class="hljs-attr">columns</span>: <span class="hljs-title class_">ProColumns</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;[] = [<br>...............<br>]<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs typescript">&lt;<span class="hljs-title class_">ProTable</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">BaseResponse</span>&lt;<span class="hljs-variable constant_">API</span>.<span class="hljs-property">CurrentUser</span>&gt;&gt;<br>  columns=&#123;columns&#125;<br>  ............<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs typescript"> <span class="hljs-comment">// 弹出异常信息</span><br>    message.<span class="hljs-title function_">error</span>(res.<span class="hljs-property">message</span>)<br>    <span class="hljs-comment">// 弹出异常描述</span><br>    message.<span class="hljs-title function_">error</span>(res.<span class="hljs-property">description</span>)<br>    <span class="hljs-comment">// 跳转至登录页</span><br>    history.<span class="hljs-title function_">replace</span>(&#123;<br>      <span class="hljs-attr">pathname</span>: <span class="hljs-string">&#x27;user/login&#x27;</span>,<br>      <span class="hljs-attr">search</span>: <span class="hljs-title function_">stringify</span>(&#123;<br>        <span class="hljs-attr">redirect</span>: location.<span class="hljs-property">pathname</span>,<br>      &#125;),<br>    &#125;);request=&#123;<span class="hljs-keyword">async</span> (params = &#123;&#125;, sort, filter) =&gt; &#123;<br>  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(sort, filter);<br>  <span class="hljs-comment">// 返回userList</span><br>  <span class="hljs-keyword">const</span> baseResponse = <span class="hljs-keyword">await</span> <span class="hljs-title function_">searchUsers</span>();<br>  <span class="hljs-keyword">return</span> &#123;<br>    <span class="hljs-attr">data</span>: baseResponse,<br>  &#125;<br>&#125;&#125;<br></code></pre></td></tr></table></figure>

<h2 id="前端封装全局请求-响应拦截器"><a href="#前端封装全局请求-响应拦截器" class="headerlink" title="前端封装全局请求/响应拦截器"></a>前端封装全局请求/响应拦截器</h2><h5 id="umi-其实已经给我们封装好了-request-了-目录-src-umi-plugin-request-request-ts-在这里我们也可以在该目录下自定义全局请求-响应拦截器-但是一方面破坏了封装组件的完整性-不好直接修改封装好的组件-我们的想法是定义自己的-requert-来封装-axios-再自定义全局请求-响应拦截器"><a href="#umi-其实已经给我们封装好了-request-了-目录-src-umi-plugin-request-request-ts-在这里我们也可以在该目录下自定义全局请求-响应拦截器-但是一方面破坏了封装组件的完整性-不好直接修改封装好的组件-我们的想法是定义自己的-requert-来封装-axios-再自定义全局请求-响应拦截器" class="headerlink" title="umi 其实已经给我们封装好了 request 了(目录:src/.umi/plugin-request/request.ts), 在这里我们也可以在该目录下自定义全局请求/响应拦截器, 但是一方面破坏了封装组件的完整性, 不好直接修改封装好的组件. 我们的想法是定义自己的 requert 来封装 axios, 再自定义全局请求/响应拦截器"></a>umi 其实已经给我们封装好了 request 了(目录:src/.umi/plugin-request/request.ts), 在这里我们也可以在该目录下自定义全局请求/响应拦截器, 但是一方面破坏了封装组件的完整性, 不好直接修改封装好的组件. 我们的想法是定义自己的 requert 来封装 axios, 再自定义全局请求/响应拦截器</h5><h5 id="新建目录-src-plugins-globalRequest-ts"><a href="#新建目录-src-plugins-globalRequest-ts" class="headerlink" title="新建目录: src/plugins/globalRequest.ts"></a>新建目录: src/plugins/globalRequest.ts</h5><h5 id="在该目录下我们封装自己的-request"><a href="#在该目录下我们封装自己的-request" class="headerlink" title="在该目录下我们封装自己的 request"></a>在该目录下我们封装自己的 request</h5><figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-keyword">import</span> &#123; extend &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;umi-request&quot;</span>;<br><span class="hljs-keyword">import</span> &#123; message &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;antd&quot;</span>;<br><span class="hljs-keyword">import</span> &#123; history &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;umi&quot;</span>;<br><span class="hljs-keyword">import</span> &#123; stringify &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&quot;querystring&quot;</span>;<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 配置request请求时的默认参数</span><br><span class="hljs-comment"> */</span><br><span class="hljs-keyword">const</span> request = <span class="hljs-title function_">extend</span>(&#123;<br>  <span class="hljs-attr">credentials</span>: <span class="hljs-string">&quot;include&quot;</span>, <span class="hljs-comment">// 默认请求是否带上cookie</span><br>  <span class="hljs-comment">// requestType: &#x27;form&#x27;,</span><br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 全局请求拦截器</span><br><span class="hljs-comment"> */</span><br>request.<span class="hljs-property">interceptors</span>.<span class="hljs-property">request</span>.<span class="hljs-title function_">use</span>((url, options): <span class="hljs-function"><span class="hljs-params">any</span> =&gt;</span> &#123;<br>  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`do request url = <span class="hljs-subst">$&#123;url&#125;</span>`</span>);<br>  <span class="hljs-keyword">return</span> &#123;<br>    url,<br>    <span class="hljs-attr">options</span>: &#123;<br>      ...options,<br>      <span class="hljs-attr">headers</span>: &#123;&#125;,<br>    &#125;,<br>  &#125;;<br>&#125;);<br></code></pre></td></tr></table></figure>

<figure class="highlight typescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs typescript"><span class="hljs-comment">/**</span><br><span class="hljs-comment"> * 全局响应拦截器</span><br><span class="hljs-comment"> */</span><br>request.<span class="hljs-property">interceptors</span>.<span class="hljs-property">response</span>.<span class="hljs-title function_">use</span>(<span class="hljs-keyword">async</span> (response, options): <span class="hljs-title class_">Promise</span>&lt;<span class="hljs-built_in">any</span>&gt; =&gt; &#123;<br>  <span class="hljs-keyword">const</span> res = <span class="hljs-keyword">await</span> response.<span class="hljs-title function_">clone</span>().<span class="hljs-title function_">json</span>();<br>  <span class="hljs-comment">// 1.返回成功状态</span><br>  <span class="hljs-keyword">if</span> (res.<span class="hljs-property">code</span> === <span class="hljs-number">0</span> &amp;&amp; res.<span class="hljs-property">data</span> &gt; <span class="hljs-number">0</span>) &#123;<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(res.<span class="hljs-property">message</span>);<br>    <span class="hljs-keyword">return</span> res.<span class="hljs-property">data</span>;<br>  &#125;<br>  <span class="hljs-comment">// 2.返回失败状态</span><br>  <span class="hljs-keyword">if</span> (res.<span class="hljs-property">code</span> === <span class="hljs-number">50001</span>) &#123;<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;...&quot;</span>);<br>    <span class="hljs-comment">// 弹出异常信息</span><br>    message.<span class="hljs-title function_">error</span>(res.<span class="hljs-property">message</span>);<br>    <span class="hljs-comment">// 弹出异常描述</span><br>    <span class="hljs-comment">// message.error(res.description)</span><br>    <span class="hljs-comment">// 跳转至登录页</span><br>    history.<span class="hljs-title function_">replace</span>(&#123;<br>      <span class="hljs-attr">pathname</span>: <span class="hljs-string">&quot;user/login&quot;</span>,<br>      <span class="hljs-attr">search</span>: <span class="hljs-title function_">stringify</span>(&#123;<br>        <span class="hljs-attr">redirect</span>: location.<span class="hljs-property">pathname</span>,<br>      &#125;),<br>    &#125;);<br>    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;code: &quot;</span> + res.<span class="hljs-property">code</span>);<br>  &#125;<br><br>  <span class="hljs-keyword">return</span> res.<span class="hljs-property">data</span>;<br>&#125;);<br></code></pre></td></tr></table></figure>

<h5 id="最后不要忘了-在-src-services-ant-design-pro-api-ts-目录下引入我们自己实现的-request-覆盖掉-umi-封装的-request"><a href="#最后不要忘了-在-src-services-ant-design-pro-api-ts-目录下引入我们自己实现的-request-覆盖掉-umi-封装的-request" class="headerlink" title="最后不要忘了, 在 src/services/ant-design-pro/api.ts 目录下引入我们自己实现的 request, 覆盖掉 umi 封装的 request"></a>最后不要忘了, 在 src/services/ant-design-pro/api.ts 目录下引入我们自己实现的 request, 覆盖掉 umi 封装的 request</h5><figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs clean"><span class="hljs-keyword">import</span> request <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@/plugins/globalRequest&#x27;</span>;<br></code></pre></td></tr></table></figure>

<h5 id="我们实现了自定义的前端全局请求-响应拦截器"><a href="#我们实现了自定义的前端全局请求-响应拦截器" class="headerlink" title="我们实现了自定义的前端全局请求/响应拦截器"></a>我们实现了自定义的前端全局请求/响应拦截器</h5><h1 id="至此-用户中心系统基本功能已经完成"><a href="#至此-用户中心系统基本功能已经完成" class="headerlink" title="至此, 用户中心系统基本功能已经完成"></a>至此, 用户中心系统基本功能已经完成</h1><h4 id="未来的持续优化"><a href="#未来的持续优化" class="headerlink" title="未来的持续优化:"></a>未来的持续优化:</h4><ul>
<li><h5 id="完善框架搭建和数据库设计的文档编写"><a href="#完善框架搭建和数据库设计的文档编写" class="headerlink" title="完善框架搭建和数据库设计的文档编写"></a>完善框架搭建和数据库设计的文档编写</h5></li>
<li><h5 id="注册的新用户会有默认的头像和昵称"><a href="#注册的新用户会有默认的头像和昵称" class="headerlink" title="注册的新用户会有默认的头像和昵称"></a>注册的新用户会有默认的头像和昵称</h5></li>
<li><h5 id="用户登录后可以更改个人信息"><a href="#用户登录后可以更改个人信息" class="headerlink" title="用户登录后可以更改个人信息"></a>用户登录后可以更改个人信息</h5></li>
<li><h5 id="完善前端全局异常处理器所处理的异常类型"><a href="#完善前端全局异常处理器所处理的异常类型" class="headerlink" title="完善前端全局异常处理器所处理的异常类型"></a>完善前端全局异常处理器所处理的异常类型</h5></li>
<li><h5 id="项目的部署和上线"><a href="#项目的部署和上线" class="headerlink" title="项目的部署和上线"></a>项目的部署和上线</h5></li>
</ul>
<h4 id="废话不多说-开启-伙伴匹配系统-的学习-（2023-04-21）"><a href="#废话不多说-开启-伙伴匹配系统-的学习-（2023-04-21）" class="headerlink" title="废话不多说, 开启 伙伴匹配系统 的学习 （2023/04/21）"></a>废话不多说, 开启 伙伴匹配系统 的学习 （2023/04/21）</h4><h2 id="项目部署"><a href="#项目部署" class="headerlink" title="项目部署"></a>项目部署</h2><h3 id="前端多环境配置"><a href="#前端多环境配置" class="headerlink" title="前端多环境配置"></a>前端多环境配置</h3><h3 id="后端多环境配置"><a href="#后端多环境配置" class="headerlink" title="后端多环境配置"></a>后端多环境配置</h3><h2 id="项目上线"><a href="#项目上线" class="headerlink" title="项目上线"></a>项目上线</h2>
                
              </div>
            
            <hr/>
            <div>
              <!-- 文章页面 - 底部标签 -->
<div class="post-metas my-3">
  
  <div class="post-meta mr-3 d-flex align-items-center">
    <i class="iconfont icon-category"></i>
    <!-- 归档页 - 文章列表 -->


<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/blog/categories/%E9%A1%B9%E7%9B%AE%E5%BF%97%E5%BD%95/" class="category-chain-item">项目志录</a>
  
  

      </span>
    
  
</span>

  </div>
   
  <div class="post-meta">
    <i class="iconfont icon-tags"></i>
    
    <a href="/blog/tags/%E9%A1%B9%E7%9B%AE/">#项目</a>
    
    <a href="/blog/tags/%E5%BC%80%E5%8F%91%E7%BB%8F%E9%AA%8C/">#开发经验</a>
    
  </div>
  
</div>


              <!-- 文章页面 - 底部标签下方 -->

  
  <div class="license-box my-3">
    <div class="license-title">
      <div>项目志录：Memory 用户中心中心开发文档</div>
      <div>https://test.atomgit.net/blog/2023/03/17/项目志录：Memory 用户中心系统开发文档/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Memory</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年3月17日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年4月21日</div>
        </div>
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/blog/2023/03/19/MySQL%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AE/" title="MySQL安装配置">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">MySQL安装配置</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/blog/2023/03/17/%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97%EF%BC%9A%E6%8E%8C%E6%8F%A1Git%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C%E5%8F%8A%E8%BF%9B%E9%98%B6%E5%AD%A6%E4%B9%A0/" title="入门指南：掌握Git的基本操作及进阶学习">
                        <span class="hidden-mobile">入门指南：掌握Git的基本操作及进阶学习</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            <!-- 文章页 - 评论上方 -->

  
  
    <article id="comments">
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"T1hUHH9Ks1ggG9DBE3HgUPpV-gzGzoHsz","appKey":"XFkgzzvzNo3J3uNCbBiSOFKc","path":"window.location.pathname","placeholder":"填取QQ号和邮箱后评论，支持读取头像及消息提醒，留下点什么叭... ᶘ ᵒᴥᵒᶅ","avatar":"Gravatar","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":true,"recordIP":false,"serverURLs":"https://t1huhh9k.lc-cn-n1-shared.com","emojiCDN":null,"emojiMaps":null,"enableQQ":true,"master":"8c9b6d6637904da62d74d019cc6982de","friends":"0188229a9cfc284176ea9135cb9514cc","visitor":true},
          {
            el: "#valine",
            path: window.location.pathname,
            app_id: "",
            app_key: "",
            placeholder: "填取QQ号和邮箱后评论，支持读取头像及消息提醒，留下点什么叭... ᶘ ᵒᴥᵒᶅ",
            avatar: "Gravatar",
            meta: ["nick","mail","link"],
            pageSize: "10",
            lang: "zh-CN",
            highlight: true,
            recordIP: false,
            serverURLs: "https://t1huhh9k.lc-cn-n1-shared.com",

            // 设置Bilibili表情包地址
            emojiCDN: '//i0.hdslb.com/bfs/emote/', 
            // 表情title和图片映射
            emojiMaps: {
                "tv_白眼": "48f75163437445665a9be80bb316e4cb252c5415.gif@48w_48h.webp",
                "tv_doge": "302d6c88c63ed162c81a49cafe7ed2709e6fb955.gif@48w_48h.webp",
                "tv_坏笑": "5d2572efd09aab5dde9e2a198bb3f9ac1e2a982e.gif@48w_48h.webp",
                "tv_难过": "9c6b41008a67755410f712334c64313df5f91b3f.gif@48w_48h.webp",
                "tv_生气": "1902a5a2df5b5c931d88c12f0feb264b1e109d0d.gif@48w_48h.webp",
                "tv_委屈": "af5a5853edb43a8178a8cb5df707fa5e88143699.gif@48w_48h.webp",
                "tv_斜眼笑": "c66568b471192ca1f62f6ed4384dc1b283ab7508.gif@48w_48h.webp",
                "tv_呆": "d3fa91e4db9215eb1e20ab9da44f1214aa4bda7b.gif@48w_48h.webp",
                "tv_发怒": "3959eb81b952e4fa8d269d98f9e3639172d84073.gif@48w_48h.webp",
                "tv_呕吐": "db58e9442aae26694af18cc1683607cca3a16763.gif@48w_48h.webp",
                "tv_思考": "b63f9146bfd985af014f8d6d4bdb498805be48f9.gif@48w_48h.webp",
                "tv_微笑": "b98656855d782f61cb8edc7f7fca6563ecafff7e.gif@48w_48h.webp",
                "tv_疑问": "fce1b1a0f3b0e39a2dc16a18508dba7b91e929f4.gif@48w_48h.webp",
                "tv_大哭": "cba61f05f3039b02a7ffc0dfcd9d7995df9fdd74.gif@48w_48h.webp",
                "tv_鼓掌": "be106e6b265883a9f28fbe10f7b765701e2618d4.gif@48w_48h.webp",
                "tv_抠鼻": "696d9f93e722144dc2a78aeffc569418fdf3d565.gif@48w_48h.webp",
                "tv_亲亲": "3534ea44ab74bd20352b88c245a06c4b4c46d271.gif@48w_48h.webp",
                "tv_调皮": "fcd967395fd14e4dd5829fa7e8a967ce23205e52.gif@48w_48h.webp",
                "tv_笑哭": "1c2fd1e8c9dde12812f86e5d4cbddd8993d98082.gif@48w_48h.webp",
                "tv_晕": "030040ec5c9ddc9e3d067658c4139e7314ab42f8.gif@48w_48h.webp",
                "tv_点赞": "30ecff401245fb56bcc1cf588d1809ac1ab1607c.gif@48w_48h.webp",
                "tv_害羞": "411a3e459e8580f5bfd9f639a408247c4b509935.gif@48w_48h.webp",
                "tv_睡着": "3c8b5e293261287a6203597e29b3de07df4d18c6.gif@48w_48h.webp",
                "tv_色": "a0c6d99ab0ab63b8648f5283ff72cec04b604828.gif@48w_48h.webp",
                "tv_吐血": "e17e4539e169d14a3389ff147afea760cebe5de5.gif@48w_48h.webp",
                "tv_无奈": "eb4cb5f07cfd177c7e6a7914316717e56d9cc1d0.gif@48w_48h.webp",
                "tv_再见": "344f61609ecce2008520dc8a977b6169215748a9.gif@48w_48h.webp",
                "tv_流汗": "390bccec65eaff536bd5bb2a0c5b8b0bdea47334.gif@48w_48h.webp",
                "tv_偷笑": "7f11e6f7f63e79112b833bd41fa13a83d7cd8474.gif@48w_48h.webp",
                "tv_抓狂":"a476b93ecd8e94ac3257323fd822f91cef212de2.gif@48w_48h.webp",
                "tv_黑人问号":"b609adf664be33224a9923262031165ae3e34cd2.gif@48w_48h.webp",
                "tv_困":"91c2bf34ecf842d7016c01d841db3d4074bd281f.gif@48w_48h.webp",
                "tv_打脸":"b0fad4856e59c1240e448437da3287bb5ce547e5.gif@48w_48h.webp",
                "tv_闭嘴":"a3fc5388b09e945be3f18fe23bfed5874a0285b7.gif@48w_48h.webp",
                "tv_鄙视":"293b5d459e6264ecf314d20937a936fa672ccd1e.gif@48w_48h.webp",
                "tv_腼腆":"30984e8264324f901d19bea85dada7103b695534.gif@48w_48h.webp",
                "tv_馋":"2525c5703c594e5f0752f68db8948773caebde47.gif@48w_48h.webp",
                "tv_可爱":"f92d20f76258bc5f33fc9d7c5e2a1d41fef19a7c.gif@48w_48h.webp",
                "tv_发财":"76131e52c9b033681b4c896c6024d29ef7ec7ec2.gif@48w_48h.webp",
                "tv_生病":"beb94829fe04f1a41bd6ca611e1f6ca9ca169afa.gif@48w_48h.webp",
                "tv_流鼻血":"8ef473f74a849420da712487b2f56ecca1f695f5.gif@48w_48h.webp",
                "tv_尴尬":"e0b84ef5ee3e5b8978e584c7c5a6550c51d15f84.gif@48w_48h.webp",
                "tv_大佬":"14ca0c05382b8741940942b2430b7a8d55c02f7e.gif@48w_48h.webp",
                "tv_流泪":"7e71cde7858f0cd50d74b0264aa26db612a8a167.png@48w_48h.webp",
                "tv_冷漠":"b9cbc755c2b3ee43be07ca13de84e5b699a3f101.png@48w_48h.webp",
                "tv_皱眉":"72ccad6679fea0d14cce648b4d818e09b8ffea2d.png@48w_48h.webp",
                "tv_鬼脸":"0ffbbddf8a94d124ca2f54b360bbc04feb6bbfea.png@48w_48h.webp",
                "tv_调侃":"4bc022533ef31544ca0d72c12c808cf4a1cce3e3.png@48w_48h.webp",
                "tv_目瞪口呆":"0b8cb81a68de5d5365212c99375e7ace3e7891b7.png@48w_48h.webp",
            },

            master: "8c9b6d6637904da62d74d019cc6982de",
            friends: "0188229a9cfc284176ea9135cb9514cc",
            tagMeta: ["博主","友人","访客"],
            visitor: true // 阅读量统计
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      <!-- 文章页面 - 右侧目录 -->

  <aside class="sidebar" style="margin-left: -1rem">
    <!-- 文章页面 - 右侧目录上方 -->
<div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>



    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <!-- 博客 - 搜索框 -->
<div
  class="modal fade"
  id="modalSearch"
  tabindex="-1"
  role="dialog"
  aria-labelledby="ModalLabel"
  aria-hidden="true"
>
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">
          搜索
        </h4>
        <button
          type="button"
          id="local-search-close"
          class="close"
          data-dismiss="modal"
          aria-label="Close"
        >
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input
            type="text"
            id="local-search-input"
            class="form-control validate"
          />
          <label data-error="x" data-success="v" for="local-search-input"
            >关键词</label
          >
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
        <div class="modal fade" id="modalNotice" tabindex="-1" role="dialog" aria-hidden="true"
     style="font-family: 'Ma Shan Zheng', cursive; color: #ffffff;">
    <div class="modal-dialog modal-dialog-scrollable" role="document"
         style="font-family: 'Ma Shan Zheng', cursive;">
        <div class="modal-content" style="border-radius: 6px;">
            <!-- 公告头部 - 响应式设计 -->
            <div class="modal-header text-center"
                 style="padding: 1rem 1.5rem;border-bottom: 1px solid rgba(255,255,255,0.2)">
                <h4 class="modal-title w-100 font-weight-bold"
                    style="font-family: 'Microsoft YaHei', sans-serif;letter-spacing: 1px;text-shadow: 1px 1px 2px rgba(0,0,0,0.2);color: #ffffff;
                           font-size: 1.5rem; /* 默认PC端大小 */
                           /* 移动端适配 */
                           @media (max-width: 768px) {
                               font-size: 1.2rem;
                           }">
                    <div class="notice-title">
                        <i class="fas fa-bullhorn mr-2"> 围栏告示</i>
                    </div>
                    <small style="display: block; font-family: 'STKaiti', serif; font-size: 0.6em; color: #a0a0a0; margin-top: 3px;">
                        旧梦轻拾 · 谨识
                    </small>
                </h4>
            </div>

            <!-- 公告内容区 - 响应式设计 -->
            <div class="modal-body"
                 style="padding: 2rem; /* PC端 */
                        max-height: 70vh;
                        overflow-y: auto;
                        /* 移动端适配 */
                        @media (max-width: 768px) {
                            padding: 1rem;
                            max-height: 60vh;
                        }">
                <!-- 图片容器（响应式设计） -->
                <!--                <div class="announcement-hero"-->
                <!--                     style="margin-bottom: 2rem; /* PC端 */-->
                <!--                            /* 移动端适配 */-->
                <!--                            @media (max-width: 768px) {-->
                <!--                                margin-bottom: 1rem;-->
                <!--                            }">-->
                <!--                    <img src="http://blog.memory-life.icu/%E3%80%90%E5%93%B2%E9%A3%8E%E5%A3%81%E7%BA%B8%E3%80%91%E5%8A%A8%E6%BC%AB-%E5%A4%95%E9%98%B3%E9%93%81%E8%BD%A8.jpg"-->
                <!--                         alt="时光溯洄题图"-->
                <!--                         style="width: 100%; -->
                <!--                                max-height: 400px; /* PC端 */-->
                <!--                                object-fit: cover;-->
                <!--                                border-radius: 4px; -->
                <!--                                box-shadow: 0 2px 12px rgba(0,0,0,0.1);-->
                <!--                                /* 移动端适配 */-->
                <!--                                @media (max-width: 768px) {-->
                <!--                                    max-height: 30vh;-->
                <!--                                }"-->
                <!--                         loading="lazy">-->
                <!--                </div>-->

                <!-- 静态公告列表 - 响应式设计 -->
                <div class="announcement-list">
                    <div class="announcement-item"
                         style="margin-bottom: 2rem; /* PC端 */
                                padding: 2rem;
                                background: rgba(255,255,255,0.05);
                                border-radius: 8px;
                                /* 移动端适配 */
                                @media (max-width: 768px) {
                                    margin-bottom: 1rem;
                                    padding: 1rem;
                                }">
                        <h2 style="color: #d38532;
                                  font-weight: 600;
                                  font-size: 1.5rem; /* PC端 */
                                  margin-bottom: 1.2rem;
                                  letter-spacing: 0.5px;
                                  /* 移动端适配 */
                                  @media (max-width: 768px) {
                                      font-size: 1.2rem;
                                      margin-bottom: 1rem;
                                  }">
                            <i class="fas fa-calendar-check mr-2"></i>时光溯洄
                            <small style="display: block; font-size: 0.6em; color: #b8b8b8;text-align: right;">——
                                晨昏往事</small>
                        </h2>
                        <div style="color: #e0e0e0;
                                  line-height: 1.8; /* PC端 */
                                  font-size: 1.05rem;
                                  letter-spacing: 0.3px;
                                  /* 移动端适配 */
                                  @media (max-width: 768px) {
                                      line-height: 1.6;
                                      font-size: 0.95rem;
                                  }">
                            <!-- 内容保持不变 -->
                            <p style="margin-bottom: 1rem; text-indent: 2em;">你好。</p>
                            <!-- 其余段落内容... -->
                            <p style="margin-bottom: 1rem; text-indent: 2em;">
                                建站后的第813天，在百忙之中总算又能抽出时间来，对整个博客站点功能做整体的规划及优化完善。</p>
                            <p style="margin-bottom: 1rem; text-indent: 2em;">
                                在刚刚过去的几年时间里，往事皆以笔墨挥毫于时光素笺之上，数百天如一日，故事的书写从未间断过。</p>
                            <p style="margin-bottom: 1rem; text-indent: 2em; font-style: italic; color: #b8b8b8;">
                                时光悠悠，日月如流，过往的蹉跎岁月总在不经意间在心间回眸。</p>
                            <p style="margin-bottom: 1rem; text-indent: 2em; font-weight: 500; color: #ffffff;">
                                俯仰之间，轻舟已过万重山。</p>
                            <p style="margin-bottom: 1rem; text-indent: 2em; font-weight: 500; color: #ffffff;">
                                蹉跎之处，往事皆成云烟散。</p>
                            <p style="margin-bottom: 1rem; text-indent: 2em;">
                                这几年的时光过得太快了，好像过去这段岁月里的所有事情都发生在一瞬间。</p>
                            <p style="margin-bottom: 1rem; text-indent: 2em;">
                                这几年的时光同样太久了，久到那些时日里仿佛囊括了自己的整个前半生。</p>
                            <p style="margin-bottom: 0; text-align: right; font-size: 0.95rem; color: #a0a0a0;">——
                                八百余个昼夜，当时只道是地久天长，如今回望，不过浮光掠影间的一瞬。</p>
                        </div>
                    </div>

                    <!-- 第二个公告项 - 响应式设计 -->
                    <div class="announcement-item"
                         style="margin-bottom: 2rem; /* PC端 */
                                padding: 2rem;
                                background: rgba(255,255,255,0.05);
                                border-radius: 8px;
                                /* 移动端适配 */
                                @media (max-width: 768px) {
                                    margin-bottom: 1rem;
                                    padding: 1rem;
                                }">
                        <h2 style="color: #6cc70b;
                                  font-weight: 600;
                                  font-size: 1.5rem; /* PC端 */
                                  margin-bottom: 1.2rem;
                                  letter-spacing: 0.5px;
                                  /* 移动端适配 */
                                  @media (max-width: 768px) {
                                      font-size: 1.2rem;
                                      margin-bottom: 1rem;
                                  }">
                            <i class="fas fa-book-open mr-2"></i>墨痕新注
                            <small style="display: block; font-size: 0.6em; color: #b8b8b8;text-align: right;">——
                                待起之章</small>
                        </h2>
                        <div style="color: #e0e0e0;
                                  line-height: 1.8; /* PC端 */
                                  font-size: 1.05rem;
                                  letter-spacing: 0.3px;
                                  /* 移动端适配 */
                                  @media (max-width: 768px) {
                                      line-height: 1.6;
                                      font-size: 0.95rem;
                                  }">
                            <!-- 列表内容 - 响应式设计 -->
                            <ul style="padding-left: 1.8rem; /* PC端 */
                                      margin-bottom: 1.5rem;
                                      /* 移动端适配 */
                                      @media (max-width: 768px) {
                                          padding-left: 1.5rem;
                                          margin-bottom: 1.2rem;
                                      }">
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">溯源计划：</span>新增博文"溯源计划"，旨在用先进的数字技术留住过去的旧时光，让家族的记忆在数字云端生长发芽，全站博文数量已达90+。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">围栏告示：</span>自去年夏天站点新增了“评论回复”功能后，至今时隔十余月，在芒种前夕本站久违地上线“围栏告示”功能，本公告栏会不定时更新，持续跟进记录最新站点功能调整日志，更多精彩内容请敬请期待。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">图片查看：</span>最近几周时间里，考虑到图文流量费用收取问题，暂时关闭了七牛云对象存储私有空间访问权限，故博文内的图文无法正常预览，择日考虑开启访问权限。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">壁纸下载：</span>后续计划实现壁纸下载功能，均为个人收集的共150+超高分辨率精美壁纸，提供在线预览以及下载功能。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">阅读体验：</span>规划完善文章内分页功能，并提供“最近更新”的文章列表，计划收录更新率较高的文章，譬如：阳台日记、叙事之外、岁月如歌、游戏人生等等，尽可能多的提升在线浏览和阅读体验。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">友链完善：</span>持续优化完善友链页面，整理归档个人常用的高质量网站合集，无偿分享给有缘人。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">音乐餐厅：</span>历经十余小时不间断调研和尝试，本站成功上线”音乐餐厅”功能，目前仅收录了个人在QQ音乐平台积累的两份歌单，再匆忙也要记得点播一首喜欢的音乐，没有音乐熏陶的心灵终究是充满缺憾的。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">三言两语：</span>每张照片都是时光的便签，随手一贴就记下了那天，本站结合Mamos实现并注入留言板功能，随缘记录那些藏在照片背后的故事。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">旧梦轻拾：</span>更新全站博客文章所属分类，共设有代码锋芒、部署之道、旧梦轻拾、人间片刻等十余种分类。
                                </li>
                                <li style="margin-bottom: 0.8rem; /* PC端 */
                                         position: relative;
                                         list-style-type: none;
                                         /* 移动端适配 */
                                         @media (max-width: 768px) {
                                             margin-bottom: 0.6rem;
                                         }">
                                    <span style="position: absolute;
                                               left: -1.8rem; /* PC端 */
                                               color: #6cc70b;
                                               /* 移动端适配 */
                                               @media (max-width: 768px) {
                                                   left: -1.5rem;
                                               }">◆</span>
                                    <span style="font-weight: bolder;">方寸之间：</span>博客应用版发布，更便捷的阅读体验来了！现已正式推出独立的桌面应用程序与移动端应用程序，暂时通过网盘和代码库提供安装包。
                                </li>
                                <p style="margin-bottom: 0; text-align: right; font-size: 0.9rem; color: #8a8a8a;">
                                    此公告最后更新于：<span style="color: #6cc70b;">2025/09/30晚</span>
                                </p>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 公告页脚 - 响应式设计 -->
            <div class="modal-footer"
                 style="border-top: 1px solid rgba(255,255,255,0.2);
                        padding: 1rem 1.5rem; /* PC端 */
                        justify-content: space-between;
                        /* 移动端适配 */
                        @media (max-width: 768px) {
                            padding: 0.8rem;
                        }">
                <small style="color: #ffffff;
                            font-size: 0.9rem; /* PC端 */
                            /* 移动端适配 */
                            @media (max-width: 768px) {
                                font-size: 0.8rem;
                            }">
                    <i class="iconfont icon-pen"></i>
                    <i class="fas fa-info-circle mr-1"></i>芒种前夕 · 旅途第813天
                    · 2025/05/28
                </small>
                <button id="confirm-btn" type="button" class="btn btn-sm" data-dismiss="modal"
                        style="background: #a0a0a0;
                               color: #ffffff;
                               border-radius: 4px;
                               padding: 0.5rem 1.2rem; /* PC端 */
                               border: none;
                               font-size: 0.9rem;
                               /* 移动端适配 */
                               @media (max-width: 768px) {
                                   padding: 0.3rem 0.8rem;
                                   font-size: 0.85rem;
                               }">
                    <i class="fas fa-check mr-1" style="color: #ffffff;">心已阅</i>
                </button>
            </div>
        </div>
    </div>
</div>

<style>
  .notice-title {
    display: flex;
    align-items: center;
    white-space: nowrap;
  }

  .notice-title:before,
  .notice-title:after {
    content: "";
    flex: 1;
    height: 1px;
    background: #ddd; /* 横线颜色 */
    margin: 0 10px; /* 横线与文字的间距 */
  }
</style>


<style>
  /* 响应式模态框宽度 */
  @media (min-width: 992px) {
    #modalNotice .modal-dialog {
      max-width: 800px;
    }
  }

  @media (max-width: 991px) {
    #modalNotice .modal-dialog {
      margin: 0.5rem auto;
    }
  }
</style>

<script>
  // 页面加载完成后执行
  document.addEventListener('DOMContentLoaded', function () {
    // 检查是否首次访问
    if (!localStorage.getItem('hasShownPopup')) {
      // 动态加载notice.ejs内容
      fetch('_partials/notice.ejs')  // 替换为实际路径
        .then(response => response.text())
        .then(html => {
          // 插入到页面body末尾
          document.body.insertAdjacentHTML('beforeend', html);

          // 手动初始化Bootstrap模态框
          $('#modalNotice').modal('show');

          // 标记为已显示
          localStorage.setItem('hasShownPopup', 'true');

          // 监听关闭事件
          $('#modalNotice').on('hidden.bs.modal', function () {
            // 可选的后续处理
          });
        })
        .catch(error => {
          console.error('加载公告栏失败:', error);
          // 备用方案：显示简单弹窗
          const fallbackHTML = `
                <div class="modal-backdrop" style="/* 样式 */">
                    <div class="modal-content">/* 内容 */</div>
                </div>`;
          document.body.insertAdjacentHTML('beforeend', fallbackHTML);
        });
    }
  });
</script>

    

    
  </main>

  <footer>
    <!-- 博客 - 页脚 -->
<div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>Memory | 个人文档站点</span> </a>
<i class="iconfont icon-love"></i> <a href="https://hexo.fluid-dev.com/docs/guide/" target="_blank" rel="nofollow noopener"> <span>配置指南 | Hexo Fluid 用户手册</span> </a> 
    </div>
  

  

  
    <!-- 备案信 ICP for China -->
    <div class="beian">
  <span>
    <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
      京ICP证123456号
    </a>
  </span>
  
    
      <span>
        <a
          href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
          rel="nofollow noopener"
          class="beian-police"
          target="_blank"
        >
          
            <span style="visibility: hidden; width: 0">|</span>
            <img src="/blog/img/police_beian.png" alt="police-icon"/>
          
          <span>京公网安备12345678号</span>
        </a>
      </span>
    
  
</div>

  

  

</div>

<!-- 评论框美化 -->
<style>
    #comments .veditor{
        min-height: 20vh;
        background-image: url(http://blog.memory-life.icu/pathway0716.jpg);
        background-size: contain;
        background-repeat: no-repeat;
        background-position: right;
        background-color: rgba(255,255,255,0);
        resize: none;}
</style>

<script>
    //   自定义邮箱审核规则
    document.body.addEventListener('click', function(e) {
        if (e.target.classList.contains('vsubmit')) {
            const email = document.querySelector('input[type=email]');
            const nick = document.querySelector('input[name=nick]');
            const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if (!email.value || !nick.value || !reg.test(email.value)) {
                const str = `<div class="valert text-center"><div class="vtext">请填写正确的昵称和邮箱！</div></div>`;
                const vmark = document.querySelector('.vmark');
                vmark.innerHTML = str;
                vmark.style.display = 'block';
                setTimeout(function() {
                    vmark.style.display = 'none';
                    vmark.innerHTML = '';
                }, 2500);
            }
        }
    })
</script>



  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/blog/js/events.js" ></script>
<script  src="/blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>







  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/blog/js/local-search.js" ></script>

  <script defer src="/blog/js/leancloud.js" ></script>




    
<script src="https://cdn.jsdelivr.net/npm/aplayer@1.10.1/dist/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
